I am building a Loot Manager script which is going to subscribe to the “enemy killed” event and spawn a corresponding Loot item in the scene. I plan to have this script as a MonoBehaviour component sitting on an empty object in the scene. I am looking for a good way to store references to loot item assets, at least reference an image of the loot.
I know that prefabs are loaded into memory if you just reference it from the public property on a game object in a scene, even though you don’t call Instantiate on that prefab. Therefore I don’t want to have an array of prefabs on my Loot Manager script. Instead, I am thinking about 2 options:
- Do a Resource.Load() of a loot’s image dynamically
- Have an array of Scriptable Objects holding loot’s image and other properties.
I personally like option #2 better, but I have some concerns about it. I don’t really know if having a game object referencing scriptable objects will lead to loading of all loot assets upfront, even those that would never get spawned on the current level? Or referencing a Scriptable Object would simply work as calling Resource.Load() when I need to reference a specific loot item from the array?