Force child object position updates before Update()

I’ve got a prefab with lots of child objects that is part of a procedural mesh system. When a prefab is instantiated, the meshes are computed. However, before the first Update() call that follows this, I need to get the positions of a few of those child objects so I can do some computations on them in order to calculate mass properties that depend on those positions. The trouble I’m having at the moment is that these positions are not being updated until (what looks like) the next Update() call. This is too late, I need to compute it immediately.

I’m wondering if there is a way to force Unity to update all the child object positions after they have been created, but before the next Update() call. If not, I’ll have to rethink a couple things.

Is this before EVERY Update call?

Or is this before the FIRST Update call?

Because ‘Start’ is called before the first update call.

If it’s required before the others Update, every Update. Well you can changed the Execution Order of the script that has to be ran first to be ran first.

1 Like

There is also LateUpdate, generally designed for cal a that must happen after the moving has stopped.

Finally you can set up your own Update loop with hooks for early, mid and late updates.

This is before the first update after a scene is loaded, only then. I’m doing this in a script that’s executed early.

Not sure, but the object I’m having troubles with is on an IK object so perhaps it’s not updated that first frame properly. Will take a look next session. I was just wondering if anybody knew a trick to force the positions to recompute. I ran across one trick with something physics related where calling Translate(Vector3.zero) would trigger something to recompute, was just wondering if there might be something similar on the regular object side.

If I skip the first graphics frame it updates correctly, but this won’t work in my application for other reasons. So it seems something isn’t getting updated until after one frame. Not sure, maybe it’s the IK.

I just tried moving the problem object to a non-IK object and that seemed to fix it. The problem object was the center of gravity position of the driver which I had attached to the driver hip object that was in the IK hierarchy. I’m not sure how the IK works, but I seem to remember a lot of it being in LateUpdate(). Probably what was happening is that the object was being updated after my computations by the IK system. That would make some sense.

“Solved it” by moving the driver center of gravity position object to another object that’s not controlled by the IK. That’ll do.

Thanks for the input, guys.