Events & tokens

AzEvent<T>

Use payload events for small values, object references, and ordinary gameplay data.

  • Payload values
  • Small structs
  • References
  • Default choice

Use AzEvent<T> when an event carries a small value, reference, or cheap-to-copy payload.

Use AzEvent<T> for Small Payloads

Use AzEvent<T> for simple values, object references, and small structs that are cheap to pass by value.

public static readonly AzEvent<int> AmmoChanged = new();

public void SpendAmmo(int ammo)
{
    AmmoChanged.Invoke(ammo);
}

private void OnEnable()
{
    GameEvents.AmmoChanged.Subscribe(OnAmmoChanged).AddTo(_subscriptions);
}

private void OnAmmoChanged(int ammo)
{
    Debug.Log($"Ammo: {ammo}");
}

Good examples:

  • int
  • float
  • bool
  • enum
  • object references like GameObject, Transform, or your own reference types
  • small structs such as an id plus a value