Give Page Feedback | API

Execution Controllers - Overview

Execution Controller's give you control over the execution of any component (the Using Component) that uses them (currently only World Components). There are two ways that the controller can affect the execution of a Using Component:

1) It can return false when its ShouldStartExecuting method is queried, which stops the Using Component from performing any updates in the current frame.

2) It can return false when its ShouldContinueExecuting method is queried, which halts the Using Component's execution in the current frame.

It should be noted that internally, a World updates itself using an enumerator based update loop. When it first begins execution, it queries the Execution Controller's ShouldStartExecuting method. Once that returns true, it enters a loop which is able to execute other enumerators (usually a garbage free process). Whenever one of these enumerators yields, it's Current property (which is always an instance of a YieldInstruction, or null) is queried by the World in order to determine its next step, which will be one of the following:

1) If Current is the special YieldOrContinue type, the World queries the Execution Controller's ShouldContinueExecuting method. If that method returns true, the World continues executing the enumerator. If it returns false, the world yields for a frame and then queries the Execution Controller's ShouldStartExecuting method the following frame in order to determine if it can resume executing the enumerator.

2) If Current is the special type YieldUntilJobComplete, the World yields until the Job Handle stored in the YieldUntilJobComplete instance is completed. Once the job finishes, the World queries ShouldStartExecuting again to determine if it can resume execution.

3) If Current is not null and not one of the types specified in 1 or 2, then the World yields according to type of Current (for example, if Current is a YieldForSeconds object, the World yields for the seconds specified). ShouldStartExecuting is queried whenever control returns to the World.

4) If Current is null, the World automatically yields for a frame, even if ShouldContinueExecuting would return true. Again, ShouldStartExecuting is queried the next frame to determine if the World can resume executing the enumerator.

The YieldOrContinue YieldInstruction is a special instruction used by various components which are driven by the World. It's basically a way for the component that utilizes it to query whether it can continue executing within the current Frame, or whether it needs to take a break. This decision is ultimately made by the Execution Controller. You can find more information in the Yield Or Continue Section within the Secondary Non Components Chapter.

YieldOrContinue Info

Creating An Execution Controller

To use an execution controller, you can add one of the default controllers to your scene and use them, or create a custom Execution Controller. This chapter contains Sections for each option, whichever you might choose.

Assigning The Execution Controller

Currently Execution Controllers can only be assigned to a World's Execution Controller field which resides within the Optional Components window.

Remember that all of the default provided Execution Controllers are only intended to be used with a single World component. If you have multiple World's, you will need to assign unique Execution Controller component instances to each one.

The Default Execution Controller

Assigning an Execution Controller is not required. When that happens, the World creates a default Execution Controller under the hood that always returns true for ShouldStartExecuting and false for ShouldContinueExecuting. It should be noted that always returning false for ShouldContinueExecuting is a very conservative approach and will usually result in the World updating more slowly than if you had assigned an Execution Controller. It will be the best performing option, however, since the conservative approach reduces the amount of time the World uses in a single frame.