- Home /
How to destroy a object when it's off screen and re-instantiate it when it gets back on screen
I'm creating a map for a 2d strategy game, I would like to make the tiles be destroyed when off screen but to re create them when they get back on screen.
also my tiles are instantiated by script so I can easily get a reference of them. EDIT: the map is quite large I don't know if that will effect anything though
Why would you want to do this? Unnecessary destruction/instantiation is a common cause of game lag...
you would want to use an object recycler or in any case just turn the objects on or off with the setActive(). Object recycler is probably what you want if you even need to do this.
http://forum.unity3d.com/threads/stop-wasting-memory-recycle-your-objects.34582/
Your answer
Follow this Question
Related Questions
How to handle Instantiation and Destroying on an infinite runner? 1 Answer
Mouse Methods (OnMouseDown, OnMouseOver etc) stop working after certain circumstances 0 Answers
2D repeating obstacles with a random Y value 0 Answers
How to blur 2D background sprites? 0 Answers
Why are my pixel art black in game window but not in scene windows? 2 Answers