DevlogDecember 5, 2026 · 2 min read

"The referenced script on this Behaviour is missing" after copying a Unity Library folder

A clean compile, a DLL on disk, and components that still show as missing. How to detect it, fix it, and keep AI agents from chasing the wrong problem.

A game bicycle on grid paper with no front wheel, its place drawn as a dashed orange outline

When several AI agents work on one Unity project, each of them needs its own working copy. A fresh copy means a first import, and on a large project that is slow. Copying the Library folder from an existing copy is the tempting shortcut. It usually saves time, and sometimes it leaves you with this:

The referenced script (Unknown) on this Behaviour is missing!

What it looks like

The project compiles without errors. The assembly's DLL is there. Yet in scenes and prefabs, the components from one or two assemblies show up as missing.

It is easy to read this as a broken package or a bad commit. An agent that reads it that way starts editing code, reinstalling packages or reverting changes, none of which touches the cause.

How to tell it is the copy

What we saw is that the link from script file to class was stale for whole assemblies. From an editor script you can ask each MonoScript for its class with GetClass(). An empty result here and there can be normal. When every script that should have a class in an assembly returns nothing, treat that assembly as stale.

What worked for us

Force a reimport of the affected assembly's folder (or of its script folders, if it has no assembly definition):

AssetDatabase.ImportAsset(folder,
    ImportAssetOptions.ForceUpdate |
    ImportAssetOptions.ImportRecursive |
    ImportAssetOptions.ForceSynchronousImport);

Then close Unity, open it again and run the same check. The check after the restart is the one that counts. If assemblies are still stale, stop patching: you may need to delete Library and let Unity import from scratch.

Close Unity on both the source and the target before you copy.

Agent-first habits that help

The fix is small. The harder part is making sure every agent applies it the same way.

Give one command, not a paragraph of instructions. A written rule such as "copy the folder, then repair it" invites an agent to stop after the copy. Make copy, repair and verify a single step.

End with a result a machine can read. A clean compile was not proof here. Let the step end with an exit code that says ready or not ready, so no agent has to judge from a log.

Check before the work starts. If the check runs only after something looks wrong, the agent is already debugging its own change. A new working copy is ready when the check passes, not when the copy finishes.

Name the false lead. This problem looks like a package or code change. Write that down next to the check, so the next agent tests the working copy before it edits anything.

Define when to give up. If the repair fails, the agent should report it with the log and stop, not try the same thing in a loop.

One working copy per agent. Shared folders turn one agent's experiment into another agent's bug.

Queue the heavy runs. Parallel agents do not mean your machine can run parallel editors. Let them prepare work side by side and take turns for the expensive part.

The general idea of agent-first work is simple: when a mistake has cost you once, do not only write it down. Turn it into a step that checks itself.