- Home /
Do duplicate gameobjects use duplicate memory?
If I have fifty enemy gameobjects in my scene, all identical to each other, and the models of each are 40KB, will each of those be stored in memory (total 2MB) or will Unity just store one copy of the model in memory and reference it for all of them?
Answer by Eric5h5 · May 09, 2013 at 12:33 AM
It will use one copy of the model; that's why sharedMesh exists. If you change sharedMesh, you change the mesh on all models that use it.
Answer by Eugenius · May 09, 2013 at 12:23 AM
I think that if they exist as separate gameobjects, Unity will not take them as one and the same but store different copies of each. But this can be easily fixed by creating a prefab of one object and simply instantiating clones.
Or am I mistaking?
That doesn't fix the problem, if you create a prefab and instantiate 50 clones, each of those clones will be separate scene objects.
The GameObjects are separate, but the mesh is not. (Unless you specifically instantiate a copy of the mesh for each model, but you wouldn't do that unless you need a unique mesh for each object for some reason--maybe if you're doing destructible meshes or something.)