I’ve a function that works like this.
if (event is true)
{
m_listOfObjects.Clear();
CreateNewListOfObjects();
}
It appears as though CreateNewListOfObjects() is called before everything in m_listOfObjects is cleared.
Calling the two functions manually with keyboard inputs with a short time in between each gave the desired result.
I don’t think this is the first time I’ve run into this problem before, but I don’t remember ever dealing with it, so if anyone has any advice on how to tackle this I’d be greatly appreciative.
All Objects are instantiated and share the same parent.
Some children of this parent have children of their own.
All child objects are destroyed before parents.
I was wondering if a Wait coroutine could work.
hmm…I’m assuming m_listOfObjects is a list.
I’m just a little suspicious that this is what is happening, but without seeing more I couldn’t tell you. (basically how is the bit of code you showed being used) I haven’t ever experienced the problem myself. Are you doing a debug at the start of CreateNewListOfObjects to print out the Count on your list?
What is happening that makes you think there is an issue?
m_listOfObjects is a class with functions for adding, changing and removing child objects to the transformer.
This is the code I’m using to have all children and parents stored in the main gameobject cleared.
public void Clear()
{
foreach (TileParent item in m_tileBatch) {
if (item) item.Clear();
}
int childCount = transform.childCount;
for (int i = childCount - 1; i >= 0; i--) {
Destroy(transform.GetChild(i).gameObject);
}
//reset tile array
m_tileBatch = new TileParent[cMapScale, cMapScale];
}
Debug.log(transform.childCount); before and after calling the Clear method returned the same number of some 600+, but all the objects in the hierarchy are removed.
EDIT Fixed my problem by turning a tile generator method into a coroutine and adding times to wait.