Skip to main content

Schedule, Repeat, and Cancel GES Events

TinyGiants
Unity Games & Tools Developer

Give a bomb a fuse by scheduling its explosion with RaiseDelayed. Keep the returned ScheduleHandle so defusing can cancel that exact request. The same handle pattern also works for repeated effects such as poison ticks.

Schedule a fuse and cancel it​

Assign a parameterless GameEvent to onExplode. Bind the event to the explosion action, then call Arm() when the bomb is placed. The returned ScheduleHandle identifies that scheduled raise. If the player defuses the bomb or its owner is disabled, cancel the handle.

using TinyGiants.GES.Runtime;
using UnityEngine;

public class BombFuse : MonoBehaviour
{
[GameEventDropdown, SerializeField] private GameEvent onExplode;
[SerializeField] private float fuseSeconds = 2f;
private ScheduleHandle fuse;

public void Arm()
{
Defuse();
fuse = onExplode.RaiseDelayed(fuseSeconds);
fuse.OnCompleted += ClearFuse;
fuse.OnCancelled += ClearFuse;
}

public void Defuse()
{
var currentFuse = fuse;
fuse = null;
currentFuse?.Cancel();
}

private void ClearFuse() => fuse = null;
private void OnDisable() => Defuse();
}

In Play Mode, arm the bomb and wait for the explosion callback. Arm it again and call Defuse() before the delay expires. The explosion should only run in the first test.

Repeat an event for a fixed number of ticks​

For damage over time, use RaiseRepeating. This example expects onPoisonTick to be a parameterless GameEvent already bound to the damage callback. The first tick runs after the interval. OnStep receives the number of ticks that have executed.

ScheduleHandle poison = onPoisonTick.RaiseRepeating(1f, repeatCount: 3);
poison.OnStep += count => Debug.Log($"Applied poison tick {count}");
poison.OnCompleted += () => Debug.Log("Poison finished");
poison.OnCancelled += () => Debug.Log("Poison cancelled");

Retain the handle on the owner when a cleanse effect must stop the ticks. Use repeatCount: -1 for an indefinite schedule and cancel it when its owner is done. Use CancelDelayed(handle), CancelRepeating(handle), or the handle's Cancel() to cancel a specific scheduled raise. Cancel() returns true if the scheduler found and stopped it.

Configure timing in Game Event Behavior​

For timing shared by callers of Raise(), configure Action Delay, Repeat Interval, and Repeat Count under Schedule Configuration. A delay with the interval set to zero schedules one action. Set a positive interval to repeat and use the repeat count to choose when it stops.

Timing fields in Game Event Behavior

With both delay and interval set, the first repeating action runs after the delay plus one interval. When calling RaiseDelayed or RaiseRepeating directly, pass the timing for that call in code.

Open the scheduling API guide · Run the delayed-event demo