- Home /
The question is answered, right answer was accepted
How do I go up from child to parent?
I am assuming I switch between hierarchy levels to accomplish tasks on each gameObject. I don't want to change the child's parent to another parent. I want 'navigate up' to the child's parent as in I want to change 'to' the child's parent.
I have this code:
// We can use a 'current' transform to help transverse
Transform current = transform; // current transform is Ring Gen
Debug.Log(current.name);
current = current.GetChild(0); // current transform is now RingPair (0)
Debug.Log(current.name);
current = current.GetChild(0); // current transform is now TSPair (0) Pos
Debug.Log(current.name);
current = current.GetChild(0); // current transform is now TSPivot (0)
Debug.Log(current.name);
//this current gets null when clearly there are
current = transform.parent; // Navigates up one to TSPair(n) level
Debug.Log(current.name);
The transform.parent is not going up to that childs parent. Null is returned in last debug line.
Thank you.
I know there are some who frown on asking questions in comments but this is where the rubber meets the road deep in an understanding of the original question posted. Concerning this question how is 'transform.parent' different from 'current.parent'? Obviously I am missing a revalent level of understanding about this.
Answer by GenericToast · Feb 08, 2019 at 07:39 AM
Shouldn't it be
current = current.parent;
What you're doing now is getting the parent of Ring Gen