There is a prefab in the project, there is at least one link to it in the scene, conditionally:
... public GameObject prefab; ...
Question : in what memory is this object stored?
There is a prefab in the project, there is at least one link to it in the scene, conditionally:
... public GameObject prefab; ...
Question : in what memory is this object stored?
In order not to guess, let's make a benchmark, since Unity has an excellent profiler.
What the profiler shows on an absolutely empty stage:
Let's create some random prefab and assign some scripts to it. Add an empty object with a simple script that references this prefab. Open debugger:
In fact, almost all of these figures are unstable, but we can be calm and judge by the parameters of the number of meshes and materials: when the prefab reference with 1 material and several meshes (the first model from Google) increased, the values:
Based on the data above, we can draw the following conclusion:
If the prefab is instantiated through a link - Unity loads during scene loading
Instantiate(prefab_reference);
If the prefab is instantiated through the resource folder, Unity will load it before instantiating , and recursive
Instantiate(Resources.Load("Prefabs/PrefabNameHere"));
If prefab number 1 is loaded from disk and in this case refers to prefab number 2 - prefab number 2 will be loaded when loading prefab number 1
And in all 3 situations, prefabs will be loaded recursively, until all, obviously, unique objects to which there are links are in memory.
The prefab will be loaded completely, not piece by piece , all the components at once, and not just a bare Transform
with the subsequent loading of the remaining components. Theoretically, the Total Objects in Scene
graph, which has grown from 205 to 218, theoretically speaks of this.
A prefab is one of the types of resources intended for reuse and stored in the Project View. A prefab can be inserted into any number of scenes and repeatedly into one scene. When a prefab is added to a scene, an instance is created. All copies are links to the original prefab and in fact its clones. Regardless of how many copies there are in a project, when you change a prefab, all its instances change accordingly.
Source: https://ru.stackoverflow.com/questions/957777/
All Articles