Reusing Nodes vs Deleting and recreating nodes ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tux

I have a scenario in which I need to spawn hundreds of obstacles in front of the player. I don’t need them anymore once player.transform.origin.z > player.transform.origin.z. But I need to spawn nodes continuously in front of the player.

So which is more efficient:-

  1. Deleting unneeded node and creating new Node
  2. disabling node (by removing it from the tree since there is no enabled property like Unity) and re-enabling it (adding it again to the tree) and changing its position
:bust_in_silhouette: Reply From: phiz

In terms of performance I don’t think it will matter as long as you manage the total number of objects. In my experience it’s been simpler to keep independant “spawning” and “despawning” logic. Might well depend on what you want to do with your project though.