FixedUpdate after Animation - Physics Loop

It seems that the built in animations play after other scripted FixedUpdate loops when 'Animate Physics' is selected - resulting in funny looking behaviour when moving a character in relation to these objects.

Is there a way to enforce the order animations will play in relation to another FixedUpdate loop? And if not, does it always execute after other FixedUpdate loops?

Since there isn't a function being explicity called, I'm not sure if I can control the call order in the normal way (calling a custom update function via some manager script).

I suppose I could 'fake' it by having the animated graphics lag a frame, but that's a bit funky --- this would be the code for that:

public class AnimatedPhysicsThing : MonoBehaviour {

    public Transform physics;
    private Transform graphics;
    private Vector3 lastPosition;

    private void Awake(){
        graphics = transform;   
    }

    private void FixedUpdate(){
        graphics.position = lastPosition;
        lastPosition = theTransform.position;   
    }
}

give LateUpdate a shot: http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.LateUpdate.html

Well, in case anyone was wondering here is how you might implement LateFixedUpdate(), if you need it.

private void FixedUpdate(){
    lateFixedUpdate = true; 
}
private void LateUpdate(){
    if(lateFixedUpdate){
        lateFixedUpdate = false;
        // LateFixedUpdate code here
    }
}

Fundamentally, however, I had the animations lag a frame to solve the aforementioned issues - using similar code to that posted in the question.

I'm not sure I understand why one would want Animated physics objects to move after FixedUpdate, it seems like they should move first, and then run FixedUpdate() on everything else, otherwise the graphics appear to be a frame behind.

Since WaitForFixedUpdate()-triggered corountines consistently run after every other Behaviour’s FixedUpdate() has completed (even when a custom Script Execution Order is set), this will consistently call LateFixedUpdate() in accordance with your use-case:

// C#

void OnEnable() {
	StartCoroutine("RunLateFixedUpdate");
}
void OnDisable() {
	StopCoroutine("RunLateFixedUpdate");
}

IEnumerator RunLateFixedUpdate() {
	while (true) {
		yield return new WaitForFixedUpdate();
		LateFixedUpdate();
	}
}

void LateFixedUpdate()
{
	// do post-all-FixedUpdates stuff here
}

or

// UnityScript

function OnEnable() {
	StartCoroutine("RunLateFixedUpdate");
}
function OnDisable() {
	StopCoroutine("RunLateFixedUpdate");
}

function RunLateFixedUpdate() {
	while (true) {
		yield new WaitForFixedUpdate();
		LateFixedUpdate();
	}
}

function LateFixedUpdate()
{
	// do post-all-FixedUpdates stuff here
}

And here’s a full test script to confirm the behavior: TestLateFixedUpdate.cs

AFAICT, this still runs before the physics engine— which is probably for the best Adjusting transforms in direct response to the physic engine’s adjustments tends to lead to bigger problems.

take a look at Update Order and as Lucas said use LateUpdate or LateFixedUpdate for what you want.

I have a similar situation.

I have a sensitive bit of gameplay code that needs to: run logic tick anims update physics

Since animation seems to tick between update and lateUpdate, everything is golden under good conditions. I would like to move the logic to fixedUpdate (and eat the cost of updating animation) but I have no way to apply pre and post- anim logic in the fixed case.

I've tried a few work arounds, but it gets really messy if these things are decoupled. Since LateFixedUpdate does not exist, has anyone really implemented a decent animation-dependent physics tick solution?