- Home /
Best method for memory usage.
I Am trying to figure out a solution to this question I posted the other day.
The gist, I have a randomly generated dungeon, and now I am trying to fill it with items and such. I want to keep all thse "items" in the resource folder organized by rarity.
I thought of a few solutions but am trying to figure out the best one for performance.
1) Getcomponent: Use resource.loadall from one scripte and allow many gameobjects access that script with Getcompnent()
2) Spawn Itmes/ Gameobject.find/ Instantiate: Use resource.loadall and spawn all items in a scene somwhere. Then when I need them use Gameobject.Find and Instantiaite it as a clone.
3) Use the inspector to assign many items for access that will be used by many scripts.
4) Resource.load everytime I need and item.
Do you have a goal amount of memory that you want to keep under? I think in general it is best to load once at the beginning of a level if you level's are small enough. If you are working on a big open world then loading objects should be based on a radius around the player.
Yea I don't think my game will end up being too big, I just like to code as efficient as possible! Also this portion of code is basically in the start method so it is happening in the beginning of the level. I guess I could just try what I think is best and it should work itself out.
Note, I think I decided to make a script that manages all items in the game, assign it to one game object (which I call dungeon master!) and reference that with get component. Also early on in the game only lower rarity items will be accessible so I will control how much loads.