Legacy Documentation: Version 5.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorSceneManager.preventCrossSceneReferences

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static var preventCrossSceneReferences: bool;
public static bool preventCrossSceneReferences;

Description

Controls whether cross-Scene references are allowed in the Editor.

A cross-Scene reference is when you have multiple Scenes loaded in the Editor, and a component attached to a GameObject in one Scene has a reference to a GameObject in another Scene.

The default value for this setting is True. This means that by default, you cannot create cross-Scene references in the Unity Editor.

The reason this is prevented by default is that cross-Scene references cannot be saved in Scene files. Therefore, having the Editor prevent you from creating these references avoids the situation where your assignments cannot be saved. If you need cross-Scene references at runtime, you need to create those references at runtime - finding the objects by name, or tag, etc.

There are however certain situations where you may need to create cross-Scene references in the Editor - even though these references cannot be saved. A typical use-case for this would be if you needed to create an Editor script which should be able to operate on objects from many Scenes at once. Deactivating this setting allows you to do this.

Note however that deactivating this value does not mean cross-Scene references will be saved.

Disabling this setting means that:

1) Dragging references from a GameObject in one Scene to another GameObject's Component field in a different Scene is allowed.
2) The Object Picker (the small target icon next to most assignable fields in the inspector) will list choices from all open Scenes, instead of from only the GameObject's own Scene.
3) Warnings are no longer logged when dragging objects from one Scene to another Scene which results in cross-Scene references.