Libraries

s&box libraries

Game Events

facepunch.libevents

Strongly typed game events

About

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

eventeventsfsm

More by Facepunch

01
Player Controller thumbnail
Player Controller facepunch.playercontroller

Components for player controller

playercontrollerfirstpersonshooterhalflifequake
+0 24h
98favorites
74upvotes
95%Wilson score
02
SDF Mesh Library thumbnail
SDF Mesh Library facepunch.libsdf

Marching cubes & squares mesh generation

procgenmesh3d2d
+0 24h
28favorites
24upvotes
86%Wilson score
03
Sprite Tools (OBSOLETE) thumbnail
Sprite Tools (OBSOLETE) facepunch.spritetools

Do not use anymore, SpriteRenderer and Sprite Resource are built-in now.

2dartpixelspritetools
+0 24h
19favorites
22upvotes
79%Wilson score
04
Wheel Collider thumbnail
Wheel Collider facepunch.libwheel

No summary provided.

+0 24h
12favorites
7upvotes
32%Wilson score
05
State Machines thumbnail
State Machines facepunch.libstates

State machines using Action Graph.

fsmstatesactiongraphstatemachine
+0 24h
11favorites
14upvotes
78%Wilson score
06
Spline Tools thumbnail
Spline Tools facepunch.splinetools

Work In Progress Spline Tools.

+0 24h
10favorites
17upvotes
82%Wilson score