- Home /
When in the script lifecycle are parent-child relationships applied?
So where do the child objects inherit the position of their parents in the order of execution --http://docs.unity3d.com/uploads/Main/monobehaviour_flowchart.svg ;hence where is it best to override this inheritance? (note would prefer to keep the objects parented for organisation)
Answer by Baste · Dec 16, 2014 at 11:11 AM
It's instantaneous. Try this code:
//Don't have this set as a child of this transform when you start playing
public Transform child;
void Start() {
Vector3 childPosBefore = child.position;
child.parent = transform;
transform.position += Vector3.forward;
Vector3 childPosAfter = child.position;
Debug.Log(childPosAfter - childPosBefore);
}
The Debug.Log will print: (0.0, 0.0, 1.0)
Meaning that the child moved with the parent transform. So you cannot override the inheritance of movement, as it happens instantaneous.
If you want your child object to not move with it's parent object, you'll have to check for updates to the parent's position, and undo them locally when they happen.
Your answer
Follow this Question
Related Questions
Parenting an instantiated Prefab? 1 Answer
Making a list of obect's parents their parents from one script. 0 Answers
Getting the topmost parent 1 Answer
Crash when setting parent 1 Answer