Execute a function in LateUpdate in a fixed time

Hi Guys!
How to call a function in LateUpdate() in a fixed (constant) time like in FixedUpdate() in Unity3d C#?
Is this possible?
Thanks!

you want a LateFixedUpdate?

Basically a FixedUpdate that occurs after all other FixedUpdates have completed?

What you can do is use script execution order to make your script be the last script that gets called. It will effectively be the last one called.

If you need a mix bag, where the same script does both regular FixedUpdate AND LateFixedUpdate… well then you’re going to have to break out the LateFixedUpdate to another script.

Why I did was create a UpdateEventHooks script:

This creates a generalized event structure for easily hooking into another scripts update events. Then I created an ‘early’ and a ‘tardy’ version of the scripts that inherit from this UpdateEventHooks:

And set their respective execution orders to be the first and last:
https://github.com/lordofduct/spacepuppy-unity-framework/blob/master/SpacepuppyBase/Hooks/TardyExecutionUpdateEventHooks.cs.meta

Now in your script you can be like:

public class MyScript : MonoBehaviour
{

    private TardyExecutionUpdateEventHooks _tardyHooks;
   
    void Awake()
    {
        _tardyHooks = this.AddComponent<TardyExecutionUpdateEventHooks>();
        _tardyHooks.FixedUpdateHook += this.LateFixedUpdate;
    }
   
   
    void FixedUpdate()
    {
        //do regular update
    }
   
    void LateFixedUpdate(object sender, System.EventArgs e)
    {
        //do late update
    }
   
}
1 Like

Thank you Very Much lordofduct !!
I Will try to do this!! My desire is basically the FixedUpdate after the Animations execution (LateFixedUpdate)
Because normally is used the LateUpdate function to do things after the animation! but there is no function like this implemented to do it in a fixed time interval (sorry for my english).
Anyway…Thanks!