Hi there !
In my app, I’m spawning a lot of objects, and all of them are stored in tables in order to track them. But at some point of their life, they can be removed from the scene and of course, every time that happens, I nil their “slot” in the array.
But in the end, my table looks like something like that :
spawnObjects = {nil, nil, nil, objectInfos, nil, objectInfos, nil, nil, etc...}.
So, when I try to pause or quit the scene, running a loop through this array can take a lot of time. And even if there are actually only 4 spawned objects in the scene, it would still need to go through all the created slots (holes?) in this array in order to find them, and pause / destroy them.
-
I tried to add a condition that checks that if it has already been nilled, it would skip it, but it doesn’t seem to change anything.
-
I also considered cleaning the array everytime an object would be destroyed, and shifting all the slots in the table in order to avoind getting holes, but then, I would have to run a loop everytime I track an object with its id number : not sure it would help me then…
So, my big question is : Is there any way to avoid this ?