Custom events
Every public method with no parameters is a custom event. UI buttons, other scripts, timers and the network can call it by name.
public void Celebrate()
{
confetti.Play();
}
| Call | Runs Celebrate() |
|---|---|
| A Button's On Click → MyScript.Celebrate | on the clicking player's copy |
SendCustomEvent("Celebrate") | here, now |
SendCustomEventDelayedSeconds("Celebrate", 2f) | here, after 2 seconds |
SendCustomEventDelayedFrames("Celebrate", 1) | here, next frame |
SendCustomNetworkEvent(NetworkEventTarget.All, "Celebrate") | for everyone (Network events) |
otherScript.Celebrate() | on another script, now (Other scripts) |
- Names are case-sensitive and must match a public method with no parameters.
- Methods whose name starts with
_can be called locally but not over the network. Use this for helpers that must not be triggered by other players. - A script can have at most 64 pending delayed events.
// A repeating timer: the method schedules itself again.
public void _Tick()
{
UpdateClock();
SendCustomEventDelayedSeconds(nameof(_Tick), 1f);
}