---
title: "Game Events - s&box library"
description: "Strongly typed game events"
canonical: "https://sbox.watch/zh-cn/libraries/facepunch/libevents/"
generated_at: "2026-11-27T13:26:25.317Z"
---

# Game Events

Strongly typed game events

- 类型: 库
- 标识符: facepunch.libevents
- 创作者: Facepunch
- 规范地址: https://sbox.watch/zh-cn/libraries/facepunch/libevents/
- Markdown: https://sbox.watch/zh-cn/libraries/facepunch/libevents/index.md
- sbox.game: https://sbox.game/facepunch/libevents/
- 生成时间: 2026-11-27T13:26:25.317Z

## 统计

- 24小时热度: +0
- Terry 评分: 83%
- 收藏: 15
- 好评: 13
- 差评: 0
- 更新时间: 2024年8月11日
- 创建时间: 2024年6月11日
- 大小: 156.8 KB
- 文件: 19
- 标签: event, events, fsm

## 描述

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



## More by Facepunch

| Package | 标识符 | 玩家 | 收藏 | 好评 | 评分 | Markdown |
| --- | --- | --- | --- | --- | --- | --- |
| Player Controller | facepunch.playercontroller | 0 | 98 | 74 | 96% | https://sbox.watch/zh-cn/libraries/facepunch/playercontroller/index.md |
| SDF Mesh Library | facepunch.libsdf | 0 | 30 | 25 | 90% | https://sbox.watch/zh-cn/libraries/facepunch/libsdf/index.md |
| Sprite Tools (OBSOLETE) | facepunch.spritetools | 0 | 18 | 22 | 83% | https://sbox.watch/zh-cn/libraries/facepunch/spritetools/index.md |
| State Machines | facepunch.libstates | 0 | 13 | 17 | 86% | https://sbox.watch/zh-cn/libraries/facepunch/libstates/index.md |
| Spline Tools | facepunch.splinetools | 0 | 12 | 17 | 86% | https://sbox.watch/zh-cn/libraries/facepunch/splinetools/index.md |
| Model Viewer | facepunch.modelviewer | 0 | 9 | 9 | 77% | https://sbox.watch/zh-cn/libraries/facepunch/modelviewer/index.md |
