Ctrl+K

The Strawberry Event System

This is an advanced topic. Even if you don't understand everything right away, you can still use Strawberry's event system effectively.

What are events?

Events are a way for objects to communicate with each other without needing direct references. In standard C#, this is typically done with delegates and events:

btnExit.Click += Exit;

void Exit(object sender, EventArgs e) {
    Application.Exit();
}

Why does Strawberry have its own event system?

Strawberry is designed to be beginner-friendly and performant for indie game developers. The built-in C# event system has some limitations in a game engine context, so Strawberry provides a specialized system with several advantages.

Key Differences from C# Events

1. Automatic Memory Management

You don't need to manually unsubscribe when destroying objects. The system handles cleanup automatically when components or objects are destroyed. (Manual unsubscription is still recommended when possible.)

2. Thread Safety

All events are executed on the main thread. When you invoke an event, it is queued and processed at the appropriate time in the next frame.

3. Priority System

Subscribers can specify a priority, allowing fine control over the order in which callbacks are executed.

Event Call Times

Every event implements IStrawberryEvent which includes an EventCallTime property. This determines when during the frame the event callbacks run.

Default is EventCallTime.OnUpdate.

See more on EventCallTime

How to Use the Event System

Subscribing to Events

Subscribing and Unsubscribing to Events

Creating Custom Events

Creating your own custom events