Is it necessary to delete previously generated objects in random level generation?
I am making a game in which the the level randomly generates new objects in the scene as the player moves forward.
So is it necessary to delete/destroy the previously generated objects as the player moves forward?
Will it improve memory usage?
Thanks in advance.
Answer by tanoshimi · Mar 06, 2016 at 01:57 PM
Yes, and yes.
@tanoshimi, Thanks, but I found out a more efficient way: Object pooling. Although deleting objects seems to be a good Idea, it may cause memory spikes. Just keep the objects you need somewhere (deactivated) like in an array, then when you want to generate, select an object in random (like blue walls, red walls, corners etc.), give them random position and activate them. Also we can reuse previous objects, give them new position as player progresses.