Give Page Feedback | API

Execution Controllers - How To Create Custom Execution Controllers

If you are not satisfied with one of the default Execution Controlllers, you can create a custom Execution Controller. To do so, create a new MonoBehaviour script that derives from the ExecutionController base abstract class.

You should place your class inside of the DeepSpaceLabs.SAM namespace, which will make the ExecutionController class available and also help avoid naming conflicts with 3rd party assets or your own code.

--Special Note--
An easy way to start with your custom class is to hover over your custom class name and choose the option Show potential fixes -> Implement abstract class. This will provide default overrides for all abstract class members.

In addition, we recommend adding the following attribute above your class, which will ensure the custom execution controller is shown with other Execution Controllers in menus:

[AddComponentMenu(GlobalValues.COMPONENT_ROOT_PATH + "Execution Controllers/Custom Execution Controller Name")]

ShouldStartExecuting (Method - Implementation Required)

This method is called by the Using Component (usually a World) before it has started executing for a given Frame (usually near the start of a Frame). Return true if you want to allow the Using Component to begin/resume execution, or false if you do not want them to.

You can implement the logic to determine whether true or false is returned in whatever way you wish, however you should be cautious not to stop the Using Component from executing for too many frames, as this will slow the Using Component considerably.

ShouldContinueExecuting (Method - Implementation Required)

This method is called by the Using Component (usually a World) while it is executing to determine whether the Using Component can continue executing or needs to yield for a frame (to let other stuff run). Specifically with the World, the method is queried whenever the World encounters a special YieldOrContinue YieldInstruction. Return true if you want to allow the Using Component to continue execution, or false if you do not want it to.

You can implement the logic to determine whether true or false is returned in whatever way you wish, however if your logic favors stopping execution, do not be surprised when the Using Component's execution is slowed.

Measuring Frame Time

If your strategy for determining whether the Using Component should start or continue executing relies on measuring the amount of time a Frame has taken, it's a good idea to run the script before other scripts. You can do this by opening the Script Execution Order menu (in Project Settings), and adding your Execution Controller to the top of the list (before Default Time).