engine icon indicating copy to clipboard operation
engine copied to clipboard

Implement control over order of execution of component update and postUpdate functions

Open mvaligursky opened this issue 5 years ago • 7 comments

Currently the order of execution of update and postUpdate functions cannot be easily / at all controlled by the user, and they are likely called in order components are created / enabled. This is causing issues when you need your components to be updated in specific order - for example character first, then it's attachment, and camera that follows the character last. Currently we have access to update / postUpdate allowing 2 layer ordering, but ideally these can be ordered by individual Script name. Also, ideally there would be public API to this allowing order to be set from code.

At the moment we have "Scripts loading order", which sorts order in which scripts are initialized. Perhaps this should be used to control execution order as well.

mvaligursky avatar Feb 05 '20 14:02 mvaligursky

The scripts loading order controls the order in which scripts are loaded from the network. The execution order is the order of each script instance in the script component. If you want an update method to be called before another you have to change the order of the script instance to go before the other, not the script loading order.

vkalpias avatar Feb 05 '20 15:02 vkalpias

I see what you're saying. This allows to change order of updates of components that are added on the same entity. How about order of update for unrelated scripts on different entities? Lets say I have 2 entities, each script each:

  1. Character -> CharacterScript
  2. Camera -> CameraScript How do I change order these are executed? (update functions of them)

mvaligursky avatar Feb 05 '20 15:02 mvaligursky

In that case it is the order of the entities in the hierarchy that determines the order. Scripts are executed on each entity in the order that each entity is added to the hierarchy which would be depth first. If you want a certain script on a certain entity to be executed before another script on another entity you have to modify the entity order

vkalpias avatar Feb 05 '20 16:02 vkalpias

Or simply to guarantee order of execution always: call method of second script from first one.

Maksims avatar Feb 06 '20 07:02 Maksims

We've encountered a few scenarios recently, where controlling order would be beneficial. If script order would be based on depth-first based on hierarchy, this would allow users to control the order by ordering children where they can. For UI elements, this would not work as their z-sorting is based on the order in the graph.

Few examples:

  1. Camera follow based on character controlled by user input.
  2. Process mouse/touch input over UI elements first in a sync manner (in update), and ignore them in some cases for world ray-casting.

Maksims avatar May 14 '22 10:05 Maksims

It would be great to have a global execution or priority order, which would work across entities and components and guarantee that all scripts of a certain type are executed before or after another script type. Something like being able to define a priority which defaults to 0 if not specified.

marklundin avatar Nov 03 '23 12:11 marklundin

I support this. Would vote for including intialize/postInitialize methods as well.

LeXXik avatar Nov 04 '23 12:11 LeXXik