Example
In Unity5, assuming that a GameObject with name "SomeObject" was stored as a prefab at Assets/Resources/SomeObject.prefab
, I know that I can create an instance of the prefab as follows:
GameObject prefab = Resources.Load<GameObject>("SomeObject");
GameObject instance = GameObject.Instantiate(prefab);
Once executed, the instance
GameObject will be a copy of the original "SomeObject" prefab, and will have been placed in the current active scene with the name "SomeObject(Clone)".
As far as I understand, the GameObject prefab
represents the actual prefab asset, and any changes made to it (setting name, adding components, etc) are written to the original prefab asset, and these changes persist even after exiting editor play mode.
Questions
Since all GameObjects are normally stored in a scene, and the
scene
property onGameObject prefab
in the above example seems to be Unloaded/Invalid/Unnamed, where exactly should I consider this special GameObject to be? I seem to be able to do everything with it that I can do with normal GameObjects, short of being visible in the hierarchy/scene view.Is it effectively in some kind of limbo state, or a special PseudoScene? It seems to persist through
LoadSceneMode.Single
scene changes, but is not like the specialDontDestroyOnLoad
scene that Objects are moved to when passed intoGameObject.DontDestroyOnLoad(...)
.Are there any other noteworthy differences between
prefab
andinstance
in the above example, other than lifetime changes, the invalid scene and being different objects from one another (Having differentGetInstanceID()
, etc)?Since calling
GameObject.Instantiate(...)
onprefab
yields a GameObject that is in a valid scene, is there any way to manually create GameObjects that are in a similar 'no scene' state? I am aware that Unity intends for all GameObjects to be in scenes and so this is purely an academic question.
I have tried looking through the documentation of the functions involved, but none go into the technical details of what specifically is happening when you call Resources.Load
on a prefab resource.