Game Events

Library

Strongly typed game events

Facepunch updated 2y ago 0 MB engine 17
thumb_up 13 open_in_new View on sbox.game
Game Events

About Game Events


Easily dispatch events in your scene when stuff happens.

Basics

Declare an event type implementing with all the properties you want to pass around.

public record DamagedEvent(
    GameObject Attacker,
    GameObject Victim,
    int Damage ) : IGameEvent;

Implement for your custom event type in a .

public sealed class MyComponent : Component,
    IGameEventHandler<DamagedEvent>
{
    public void OnGameEvent( DamagedEvent eventArgs )
    {
        Log.Info( $"{eventArgs.Victim.Name} says \"Ouch!\"" );
    }
}

Dispatch the event on a or the , which will notify any components in its descendants.

GameObject.Dispatch( new DamagedEvent( attacker, victim, 50 ) );

Invocation order

You can control the order that handlers are invoked using attributes on the handler method.

* : run this first
* : run this last
* : run this before 's handler
* : run this after 's handler

[Early, After<SomeOtherComponent>]
public void OnGameEvent( DamagedEvent eventArgs )
{
    Log.Info( $"{eventArgs.Victim.Name} says \"Ouch!\"" );
}
561
Total Users
1,388
Total Sessions
3.0 days
Total Playtime

Global Statistics

15.9K
kills
0 recorded entries
Rank Player Score Recorded
refresh
Discovering package leaderboards...
Package ID: facepunch.libevents
Created: 2024-06-11 09:12 UTC
Updated: 2024-08-11 10:59 UTC
Type: library
Public: Yes
Version: 65480
files: 19
Size: 0.2 MB
Engine Version: 17
Asset Version ID: 65480
Version Created: 2024-08-11 10:59 UTC
Hash: 4045617937883951561
Manifest: Open manifest

more_horiz Additional Properties

Compiler: {"RootNamespace":"Sandbox.Events","DefineConstants":"SANDBOX;ADDON;DEBUG","NoWarn":"1701;1702;1591;","Nullables":true,"WarningsAsErrors":"","Whitelist":true,"AssemblyReferences":[],"IgnoreFolders":[],"DistinctAssemblyReferences":[]}
new_releases Latest Update Aug 11, 2024
Changes on 2024-08-11
65480 Aug 11, 2024
Changes on 2024-08-11
64781 Aug 8, 2024
Changes on 2024-08-08
64761 Aug 8, 2024
Changes on 2024-08-08
64727 Aug 8, 2024
Changes on 2024-08-08
60139 Jul 11, 2024
Changes on 2024-07-11
60137 Jul 11, 2024
Changes on 2024-07-11
60121 Jul 11, 2024
Changes on 2024-07-11
58385 Jun 13, 2024
Changes on 2024-06-13
58380 Jun 13, 2024
Changes on 2024-06-13
58357 Jun 12, 2024
Changes on 2024-06-12
info Live API Passthrough & Removal Notice

This file manifest and asset metadata are retrieved live directly from the official Facepunch s&box public API. s&box Explorer does not host, store, or redistribute any package files. All download links route directly to Facepunch CDN servers.