Registering & Unregistering Events
Basic Registration
Subscribe to an Event
using Glitch9.AIDevKit.Agents;
Agent agent = new Agent(config, settings);
// Register an event handler
var subscription = agent.RegisterEvent<AgentStatusChanged>(evt =>
{
Debug.Log($"Agent status changed to: {evt.NewStatus}");
});Unregister an Event
Method 1: Dispose the Subscription (Recommended)
var subscription = agent.RegisterEvent<AgentStatusChanged>(OnStatusChanged);
// Later, when done
subscription.Dispose();Method 2: Explicit Unregistration
Common Patterns
Single Event Handler
Multiple Event Handlers
Method Reference vs Lambda
Async Event Handlers
Event Handler Lifecycle
Component-based Lifecycle (Unity)
Class-based Lifecycle
Conditional Registration
Error Handling in Event Handlers
Event Types as Event Handlers
Best Practices
✅ Do
❌ Don't
Complete Example
Next Steps
Last updated