Moving player back to origin after LateUpdate?

Usually, the process of recentering the player (in a very large map) is supposed to be done in LateUpdate; but in my case some of my scripts (including character controllers) have a LateUpdate function. Is there a way to run it after LateUpdate? OnGUI runs after that point, but that’s apparently only called if there’s an event like a button click on a UI element, right?

See this chart:

Most likely this is the most valuable piece of information in unity docs. Or one of the most valuable pieces.

Judging by the graph LateUpdate actually IS called last before the execution moves to handling rendering, which means you’ll need to reorganize your code. Either attempt to ensure that late update code is somehow delayed till the last possible moment, or attempt to make sure that anything you want to do runs within Update when possible.

A reasonable way to run code after Update but before LateUpdate seems to be coroutines.

Ideally, however, you should avoid situations when interdependent data exists in LateUpdate.

If you really want a more complex handling of order you’ll need to implement your own “Obejct Manager” object to which your objects will register. That Object manager could then call late update functions (or their equivalent) in passes, when necessary.

3 Likes

move the script to execute later than the others in the script execution order

1 Like

Be aware hat by doing that you make your code dependent on project configuration, meaning it will break if you pull your scripts into another project.

But if you aren’t planning to migrate, or if you THINK you’ll never reuse dependent systems, this is a possible way to do it.

1 Like