Referencing instances in Prefab and Scene with SerialzieField - Katsuya100/SceneLayer-Trial GitHub Wiki

If you want to have references across Prefab/Scene/ScriptableObject instances, use the CrossReference class.
This technique is also useful when you want to have a reference to a Prefab instance that you plan to load into a Layer.

[SerializeField]
CrossReference<GameObject> _go;

It will then appear like this on the inspector.
image

Inserting an object into this field automatically creates a CrossReferenceRegister component and registers the instance.
image

When executed, the object reference can be obtained after instantiation of the target object.

Note

If a scene's GameObject is referenced and the corresponding scene is not open, the scene reference and GlobalObjectID will be displayed in the Inspector.
image

For ScriptableObject

When registering a ScriptableObject with CrossReference, the member must be set as follows.

[SerializeField]
CrossReferenceRegisterObject _crossReferenceRegister;

Then, open the Inspector of the target ScriptableObject and click on the [Register] button.
image
This will ensure that references are automatically allocated when the ScriptableObject is loaded.

⚠️ **GitHub.com Fallback** ⚠️