Seems like a silly question but… when are you supposed to release a loaded asset?
Follow-up question: is the memory consumed by a loaded asset (ie. prefab) the same amount as the instantiated game object?
The reason for my confusion is that the documentation and the posts I’ve been reading about this all seem to strongly suggest that game objects and the originating asset live and die together. The notion of a ref count via Addressables.InstantiateAsync and the Addressables.ReleaseInstance reinforces this understanding.
But if we’re trying to stingy be with memory use, why wouldn’t we just release the asset once we’ve instantiated the game object rather than wait the offspring game objects to be destroyed at a later point in time (or via the scene unload)?
Example #1:
-
Game is loading a level (scene is being loaded) - show progress bar.
-
While loading, you need to load 10 different prefabs and instantiate 1 or more game objects for each prefab.
-
After instantiation of game objects, you close the progress bar.
In this example, the ‘10 different prefabs’ will never be used again once the game objects have been instantiated. Can I release the loaded assets after Step #2?
Example #2:
- Game is loading a level (scene is being loaded) - show progress bar.
- While loading, I have 3 “projectile” prefabs and I will instantiate 100 game objects in a pool for each prefab.
- After instantiation of the game objects, you close the progress bar.
Same idea as Example #1. I have a pool of 100 game objects for each projectile. Assuming I never go beyond the allotted 100, I wouldn’t need to instantiate anymore. Again, can I release the loaded assets after Step #2?
Thanks!