Memory Managmenet

Hey guys,

I was wondering if objects are loaded into memory when they are referenced by scripts?

For example, imagine we have a single game object with a mesh renderer. On this object we have a script which allows the player to change the material to one of 10 materials. Are all 10 materials loaded into memory on level start, or are they loaded as required?

Thanks in advance! -Jack

I don’t have any reference to support this, but I’d say that they are loaded if you have a reference to it (for example if you bind it through the inspector). What you can do is place them in the Resources folder and load them dynamically, if you need to avoid having them loaded when they aren’t used.

Use Resources.Load to load any sort of asset, including materials.

See also Resources.UnloadUnusedAssets and Object.Destroy.