What I’m currently working on is to generate some trees on the land. As you can see there is nothing on the land on the left part of the image. Unfortunately, In the game design, the world is procedurally generated and stored in a local file (just like Don’t Starve or Terrarian) so I cannot drag and drop these tree prefabs in the editor.
I’ve purchased some assets with more than 200 types of tree models and I’ve generated the data of the tree location and model ID. I know the Instantiate method is the weapon to generate models in runtime. What is worrying me is how to manage these 200+ prefabs in the game.
I have some ideas but I’m not sure if I’m correct. I can create a GameObject[ ] in my TreeGeneration.cs and drag all of the prefabs in it. Every time I need to generate a new tree, I can find the prefab with the model ID and do an Instantiate.
My question is: is this the best practice? Is there another way to manage such many prefabs? Will I have some memory problems if the number of tree models explodes from 200 to 20000?
It… depends. How big are these prefabs? How much memory will the prefabs take up? Is that amount of memory acceptable for your game?
All of those questions can only be answered by you. If I were you, yes I would put all the prefabs in your treegenerator script, get your game working, and move on with my life. If I start to find later that this causes unacceptable load times or unacceptable memory usage, then I would explore alternatives.
Other alternatives would be things like Resources.Load, AssetBundles, or the Addressables system.
Thanks, @PraetorBlue . This game is in Low-Poly style and I think the memory may not be an issue. I’ll carry as you suggested and thanks again for these keywords. I can see the possible ways to improve it.