0

I am making a game that looks similar to Rimworld (top-down colony simulator) for a college project and I procedurally generate my terrain using perlin noise, then for each tile in the map I use SetTile() to populate the map with walkable terrain.

However, I am unsure of how to deal with spawning (or instantiating) objects like rocks, trees, or any other object that might be interactable with the characters walking around the map.

Is there a better (more performant or more intuitive) way of generating trees on some tiles, instead of using Instantiate(), which just fills up my entire hierarchy with tree prefabs, unlike my tilemap?

And if a character were to go chop those trees, does every tree need to have a script attached to it, or is it enough to just have a character check if that's a tree that he collided with to start chopping it?

caleidon
  • 239
  • 4
  • 13
  • You know your into is good, and you ask some direct questions but i'm lacking a clear 'problem statement'. Like the questions you ask - what would the answers to those questions solve? what are you trying to achieve? – sommmen Dec 10 '20 at 20:54
  • @sommmen My main question is if there is any more performant ways to summon tons of trees other than by straight up instantiating them, but I guess that's the way to go. – caleidon Dec 11 '20 at 12:35

1 Answers1

1

Is there a better (more performant or more intuitive) way of generating trees on some tiles, instead of using Instantiate(), which just fills up my entire hierarchy with tree prefabs, unlike my tilemap?

No I think you got it. There are ofcourse ways to optimize this process, like generating the map as the player walks (think of 'chunks' in minecraft) instead of all at once. Also why not instantiate the trees under a parent game object which is empty so you can hide it.

For example, bullets (this uses object pooling which is a subject for another time): enter image description here

And if a character were to go chop those trees, does every tree need to have a script attached to it, or is it enough to just have a character check if that's a tree that he collided with to start chopping it?

You could, or you could ofcourse handle it in your player. What you want is up to you.

sommmen
  • 6,570
  • 2
  • 30
  • 51
  • The map is entirely generated at runtime and can not be expanded afterwards. Also, the player can zoom out entirely so all the trees would need to be visible. Could you please verify what you mean by: `Also why not instantiate the trees under a parent game object which is empty so you can hide it.`? I'm using tilemaps so it would be one tree per tile its spawned on. Would you be kind to link me to a tutorial / explanation about object pooling? Would that improve performance with lots of trees? Thank you! – caleidon Dec 11 '20 at 12:33