Hi,
So I have this problem - i have a function that searches child objects by name with foreach loop and simply makes their transform.parent null, after it is done I deactivate the function with boolean, yet the problem is, doesn’t matter how many children the object has, it will always detach only a half of them and then stop.
Here’s the code, please help me if you know why it’s not working.
Thanks in advance!
void DetachChildren()
{
if(finished==false)
{
foreach(Transform child in transform)
{
if(child.gameObject.name=="ChildName")
{
child.transform.parent=null;
}
}
finished=true;
}
}