3.1 KiB
3.1 KiB
ConfigurableEventManager Implementation Guide
What is ConfigurableEventManager?
The ConfigurableEventManager is a Godot Node that provides a visual, inspector-based way to define and manage events in your game without writing code for each event.
How to Set It Up
Step 1: Add EventManager to Your Scene
- Open
Scenes/Main.tscnin Godot - The EventManager node should already be added as a child of Main
- Select the EventManager node in the scene tree
Step 2: Create GameEventResource Assets
You need to create .tres resource files that define your events:
- In Godot, right-click in the FileSystem dock → New Resource
- Search for GameEventResource and select it
- Click Create
- Save it in
Resources/Events/(you may need to create this folder)
Example event resources to create:
GameStarted.tres
- Event Name:
GameStarted - Description:
Fired when the game begins - Parameter Count:
0 - Category:
Game
ScoreChanged.tres
- Event Name:
ScoreChanged - Description:
Fired when player score changes - Parameter Count:
1 - Parameter1 Type:
int - Parameter1 Description:
The new score value - Category:
Player
PlayerLevelUp.tres
- Event Name:
PlayerLevelUp - Description:
Fired when player gains a level - Parameter Count:
2 - Parameter1 Type:
string - Parameter1 Description:
Player name - Parameter2 Type:
int - Parameter2 Description:
New level number - Category:
Player
Step 3: Configure EventManager in Inspector
- Select the EventManager node in your scene
- In the Inspector, find the Events array property
- Click to expand it and set the Size to match your number of events (e.g., 3)
- Drag your
.tresevent resource files into each array slot - Optionally enable Enable Debug Logging to see event activity in the console
Step 4: Use Events in Your Scripts
See Scripts/EventExample.cs for a complete example of:
- Getting a reference to the EventManager
- Subscribing to events
- Raising events
- Unsubscribing from events
Key Benefits
✅ Visual Configuration - Define events in the Inspector without code ✅ Type Safety - Still get compile-time checking in C# ✅ Documentation - Event descriptions and parameter info built-in ✅ Debug Logging - Optional logging for all event activity ✅ Validation - Warns if you subscribe with wrong parameter count
Usage Pattern
// 1. Get reference
_eventManager = GetNode<ConfigurableEventManager>("/root/Main/EventManager");
// 2. Subscribe
_eventManager.Subscribe<int>("ScoreChanged", OnScoreChanged);
// 3. Raise event somewhere
_eventManager.Raise("ScoreChanged", 100);
// 4. Unsubscribe when done
_eventManager.Unsubscribe<int>("ScoreChanged", OnScoreChanged);
Next Steps
- Open the project in Godot 4.5
- Create your GameEventResource assets in the editor
- Add them to the EventManager's Events array
- Use the example script as a template for your game objects
- Enable debug logging to see events firing in real-time