- Home /
Why is my array getting filled with "missing objects"
I have a function that generates room with random assets in pre-defined places. I store those assets in arrays with "FindGameObjectsWithTag" function. When I first start the scene it works flawlessly. However, when I destroy the room and everything in it ( before generating a new one, I double checked) and call the function that generates it again, FindGameObjectsWithTag function fills arrays with objects again, but usually with a few "missing objects". What's causing this?
Answer by ShadyProductions · Sep 23, 2018 at 12:13 PM
It means that the objects aren't in the scene anymore but you're still trying to reference to them inside the array.
But why is it doing that? I destroy those objects and clear the array before calling the function that finds them again...yet it still manages to find them
Answer by Tekksin · Sep 23, 2018 at 02:16 PM
Make sure to reset the int that you might be looping with in your script. Can we see your code? the problem is probably in there.
IE: if you found 5 hotspot objects, then cleared them, and then ran a loop without clearing the original int, it would start from 5.
I don't have the code anymore, I kept working on it and changed it quite a bit. I'll come back to this later if needed. Seems like it was destroying objects with a delay even though I did set the delay to 0. I fixed it by simply filling up the array on LateUpdate. Probably not the best idea but hey...it works.
Your answer
Follow this Question
Related Questions
Public Array of GameObjects 2 Answers
Array values changing after gameObject is instantiated from prefab 1 Answer
How to create an array of prefabs with a specific script attached 3 Answers
ArrayTypeMismatchException in Build, but not Editor 0 Answers
How I can replace a game object in a GameObject array ?,how to replace gameobjects of a array 1 Answer