Game Events
Facepunch Facepunch Library update 1y ago

Game Events

Strongly typed game events

favorite15favorites
thumb_up13upvotes
hard_drive 0 MB folder 19 files build Engine v17 history Last update 698d ago
open_in_new View on sbox.game

About This Package

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!\"" );
}

Media

555
Total Users
1,382
Total Sessions
3.0 days
Total Playtime

Global Statistics

10.6K
kills
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
Cs Proj Name:
Compiler: Sandbox.Events, SANDBOX;ADDON;DEBUG, 1701;1702;1591;, 1, , 1, Array, Array, Array
Resources:
Code Package References:
new_releases Latest Update Aug 11, 2024
Changes on 2024-08-11
tag v65480 folder 19 files hard_drive 0.2 MB build Engine v17
65480 Aug 11, 2024
Changes on 2024-08-11
folder 19 files hard_drive 156.81 KB build Engine v17
64781 Aug 8, 2024
Changes on 2024-08-08
folder 25 files hard_drive 209.92 KB build Engine v17
64761 Aug 8, 2024
Changes on 2024-08-08
folder 25 files hard_drive 209.49 KB build Engine v17
64727 Aug 8, 2024
Changes on 2024-08-08
folder 25 files hard_drive 207.5 KB build Engine v17
60139 Jul 11, 2024
Changes on 2024-07-11
folder 10 files hard_drive 28.79 KB build Engine v17
60137 Jul 11, 2024
Changes on 2024-07-11
folder 10 files hard_drive 28.94 KB build Engine v17
60121 Jul 11, 2024
Changes on 2024-07-11
folder 10 files hard_drive 28.21 KB build Engine v17
58385 Jun 13, 2024
Changes on 2024-06-13
folder 10 files hard_drive 28.54 KB build Engine v17
58380 Jun 13, 2024
Changes on 2024-06-13
folder 10 files hard_drive 28.2 KB build Engine v17
58357 Jun 12, 2024
Changes on 2024-06-12
folder 10 files hard_drive 27.93 KB build Engine v17