- Home /
How does resource loading and instantiating consume memory
In the game I'm making I'll eventually have a large number of resources and it likely wont be feasable to have them all loaded at the sime time. However exactly when and were I'll need certain resources is undetermined until runtime since the game is proceduraly generated. Therefore I'm making a resource manager which will help me to control this problem. I have a couple of questions though regarding resource loading and asset sharing which I wasn't able to find answers for in the docs, so I was hoping someone could shed some light for me.
Object myResource = Resources.Load("resourcePrefab");
GameObject myInstance = Instantiate(myResource) as GameObject;
In the above code, assuming that 'resourcePrefab' is a prefab which contains a mesh, what is actualy getting loaded and created in memory when? Does the 'myResource' object actualy contain the mesh loaded in memory which is then cloned when 'myInstance' is instantiated from it, or does 'myResource' simply hold a reference to the mesh file which doesn't get loaded into memory until 'myInstance' is instantiated?
Also related, if I do this:
Object myResource = Resources.Load("resourcePrefab");
GameObject myInstanceA = Instantiate(myResource) as GameObject;
GameObject myInstanceB = Instantiate(myResource) as GameObject;
will 'myInstanceA' and 'myInstanceB' share the same mesh, or will two seperate instances of the mesh have been created in memory?
Cheers
Your answer
Follow this Question
Related Questions
UnloadAsset with GameObject best practice? 0 Answers
Instantiate(GameObject) VS Instantiate(Resource.Load(Object Path)) 1 Answer
Can gameobject be exported as unity3d form? 0 Answers
Resources.Load can not get my characters visible 1 Answer
resources.load (instantiate from this.transform) rather then the centre of the map? 1 Answer