reckfellENGINE

Signals: reacting to events

Connect Button.Pressed, read state and disconnect the handler when leaving the tree.

On this page

A signal reports an event: a button was pressed, a timer expired or an object entered an area. The sender does not need to know its listeners. A direct method is usually enough for a command sent to a known object.

Connect a button in C#

Create a prefab with a Control root and a child Button named AddButton. Set the button text to +1 and its size to at least (120, 48) so it is visible. Attach ClickCounter.cs to the root:

C#
using Reckfell;

public partial class ClickCounter : Control
{
    private Button? _button;
    public int Count { get; private set; }

    public override void _EnterTree()
    {
        _button = GetEntity<Button>("AddButton");
        _button.Pressed += OnPressed;
    }

    public override void _ExitTree()
    {
        if (ReckfellObject.IsInstanceValid(_button))
            _button!.Pressed -= OnPressed;
        _button = null;
    }

    private void OnPressed()
    {
        Count++;
        ReckfellApi.Print(Count);
    }
}

Build the project and run the prefab. Three presses should print 1, 2, 3 in Output.

Pressed is a C# event backed by an engine signal. += subscribes a named method; -= removes that subscription. This example connects on every _EnterTree() and disconnects on _ExitTree(): removing and reinserting the entity does not add extra calls.

Choose one connection method

Connect a built-in signal either from the selected entity's signal list in the editor or from code. Avoid using both for the same action. A subscription is not event history: a signal emitted before connecting will not be replayed. Initialize UI from the object's current state.

Passing values and awaiting

Handler parameters must match the signal parameters. Timer.Timeout, for example, has no arguments; a custom health signal can carry a new integer value. See C# signals for [Signal], subscription lifetime and ToSignal().

If a handler does not run

Check the AddButton name, the latest build and that you ran this prefab. If the counter increments twice, look for repeated subscriptions, an editor connection or duplicate emission. When a listener outlives or leaves its sender, manage the subscription explicitly rather than assuming automatic cleanup covers every delegate.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.