Give Page Feedback | API

Execution Controllers - Frame Rate Dependent Time Sliced Controller

The Frame Rate Dependent Time Sliced Execution Controller is designed to combine the properties of the Frame Rate Dependent & Time Sliced Execution Controllers. ShouldStartExecuting will only return true if the current Frame of the game has not taken more than X seconds (where X is equal to the Execution Start Frame Time Limit value set in the inspector), or if the Using Component's execution has been suspended for Y Frames (where Y is equal to the Suspension Frame Limit value set in the inspector). Once the Using Component begins/resumes execution, the Controller's ShouldContinueExecuting method returns false only if the Using Component has been executing for more than Z seconds (where Z is equal to the Time Slice value set in the inspector).

Creating A Frame Rate Dependent Time Sliced Execution Controller Component

You can add this component by selecting a game object and then selecting from the Top Menu Bar:

Component -> Deep Space Labs -> -> SAM -> Execution Controllers -> Frame Rate Dependent Time Sliced Execution Controller

Adding A Frame Rate Dependent Time Sliced Execution Controller Component From The Top Menu Bar GIF

or by selecting a game object and using the Add Component menu via its inspector:

Component -> Deep Space Labs -> -> SAM -> Execution Controllers -> Frame Rate Dependent Time Sliced Execution Controller

Adding A Frame Rate Dependent Time Sliced Execution Controller Component From Add Component Menu GIF

Execution Start Frame Time Limit

If the current frame has taken up more than this amount of time (in seconds), the controller's ShouldStartExecuting method will return false, unless the Using Component has been suspended for Y Frames (where Y is equal to the Suspension Frame Limit value set in the inspector).

Suspension Frame Limit

In order to avoid situations where the component using this execution controller would never start executing (or only start executing after a large number of frames) because the frame time is greater than the Execution Start Frame Time Limit set, this value must be set. Once the component using the execution controller has suspended execution for a number of frames equal to this value, the next query of ShouldStartExecuting will automatically return true.

Time Slice

The amount of execution time (in seconds) per frame to try and limit the Using Component to. The amount of time a Using Component has executed is measured from the moment the Frame Rate Dependent Time Sliced Controller's ShouldStartExecuting method is queried and returns true. Once this time has surpassed the Time Slice value, the next time the Using Component encounters a YieldOrContinue YieldInstruction, it will yield for a frame.

Note that the actual time the Using Component executes in any given frame may be less than or slightly more than this specified value, as there is no guarantee that a YieldInstruction will be encountered around the specified time.

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 Worlds, you will need to assign unique Execution Controller component instances to each one.

Measuring Frame Time

The controller measures frame time by starting a Stopwatch within FixedUpdate. In order for the frame time measurement to be as accurate as possible, the controller should execute before other scripts. The controller script name should automatically be added to the Script Execution Order settings (found in Project Settings), however you may want to confirm this, and if it hasn't been added, add it. Do not place other script files above this controller, unless the script file is also measuring frame time (for instance, you can leave the Frame Rate Dependent Execution Controller above it in the Script Execution Order list).

Single Instance Per World

Each instance of the Frame Rate Dependent Time Sliced Execution Controller can only be used with a single World!