Table of Contents

Script System Extensions

Extension methods for ScriptSystem, in the Stride.CommunityToolkit.Engine namespace. They cover two jobs: awaiting time inside an async script, and scheduling work as a micro thread without writing one yourself.

Waiting

Every method here comes in a plain and a warped flavour. Warped time is scaled by the game's update time factor, so a warped wait slows down when the game does; the plain version does not.

  • Delay() - Waits the given number of seconds, ignoring the update time factor.
  • DelayWarped() - Waits the given number of seconds in game time, so slow motion stretches the wait.
  • WaitFor() - The same as Delay() but takes a TimeSpan. Throws if the delay is zero or negative.

Running something every frame for a while

  • ExecuteInTime() - Calls the action once per frame for the given number of seconds, passing the seconds elapsed so far.
  • ExecuteInWarpedTime() - The same, measured in game time rather than real time.

Scheduling micro threads

These return the MicroThread they created, so you can keep it and cancel it later. Each takes an optional priority.

  • AddAction() - Runs an action once, after a delay. A second overload adds a repeatEvery interval and keeps running it.
  • AddTask() - The async counterpart of AddAction(), taking a Func<Task>. Also has a repeating overload.
  • AddOverTimeAction() - Runs an action every frame for a duration, passing progress from 0.0f to 1.0f. This is the one to reach for when tweening something.
  • AddOnEventAction() - Runs an action every time an event is published. Takes an EventKey<T> or an existing EventReceiver<T>.
  • AddOnEventTask() - The async counterpart of AddOnEventAction().
  • CancelAll() - Cancels every micro thread in a collection and clears it. An extension on the collection, not on the script system.
Tip

When the action you pass is an instance method of a ScriptComponent, the micro thread stops on its own once that component or its entity is removed. Pass a lambda that closes over other state and you own the lifetime yourself - keep the MicroThread and cancel it.