How are prefab references loaded into memory?

Hello, quick question about assets being loaded in memory. I’ve tried using the profiler but its a bit difficult and it’s not fully answering my question.

I know when an asset is referenced as a public variable on an active gameobject, the asset is loaded into memory automatically when the scene opens. This is avoided by using Addressables, asset bundles, or store plugins.

Lets say I have 5 “Enemy Spawners” scattered around the scene. Each one has a list of different enemy prefabs, but they all contain the “Spider” enemy. What does the memory look like for this? Are there 5 copies of the Spider being loaded into memory, or is it a single instance thats just referenced by multiple sorces?

Single instance. In build prefabs will behave basically the same as inactive game objects with no parent transform.

Yep, on building, a graph of all direct relations is build and that will result in a list of assets to be loaded per scene. So yeah in the end there is a single SerializedFile copy of the prefab for loading purposes.

But, may I ask in which way the Memory Profiler was not helpful in pointing that out? Maybe there is a way for us to clarify that :slight_smile:

1 Like