🤔

Cross-scene references#

warning

Serialized references between objects cannot occur across scenes.

Cross-scene references are disallowed as they cannot be saved in Scene files and will also cause NullReferenceExceptions when both scenes are not loaded in the editor.

Resolution#

If you cannot change your architecture to avoid these references, consider constructing them in code, not serializing them directly.

Some options include:#

Each of these approaches have benefits and drawbacks, including project and code maintenance overhead. Some have pre-built approaches that you might find on a repository host or OpenUPM.

Notes#

If you are avoiding having too many things in a single scene to prevent merge conflicts, consider breaking areas down into prefabs, and make sure you have smart merge configured.

It's generally undesirable to bypass this restriction with EditorSceneManager.preventCrossSceneReferences unless you are making editor-only tooling that requires it.