Index of every page on this site: llms.txt
All skills
jame581 avatar

/csharp-signals

@426e8ab
by Jan Mesarčjame581/godotprompter979 stars
63
Run it yourself

Use when implementing signals in C# — [Signal] delegates, EmitSignal patterns, and async signal awaiting. Triggers on declaring, emitting, connecting, or awaiting a signal from a C# script, and on a signal crossing between C# and GDScript in either direction.

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/csharp-signals

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesawaiting-signals.md

≈712 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Awaiting Signals (C#)

Reference for skills/csharp-signals/SKILL.md — basic await, await with return values, timeout patterns (Task.WhenAny, CancellationTokenSource).

← Back to SKILL.md


5. Awaiting Signals

ToSignal(source, SignalName.SignalName) returns a SignalAwaiter that integrates with C#'s async/await. The method must be async and return Task (or void for fire-and-forget).

Basic await

public async void StartCutscene()
{
    // Pause normal gameplay.
    GetTree().Paused = true;

    // Wait until the animation finishes.
    await ToSignal(GetNode<AnimationPlayer>("AnimationPlayer"), AnimationPlayer.SignalName.AnimationFinished);

    GetTree().Paused = false;
    EmitSignal(SignalName.CutsceneCompleted);
}

Await with returned values

SignalAwaiter resolves to a Variant[] containing the signal's parameter values.

public async void WaitForPlayerInput()
{
    var result = await ToSignal(this, SignalName.ItemCollected);
    string collectedName = result[0].AsString();
    GD.Print($"Player collected: {collectedName}");
}

Timeout pattern with Task.WhenAny

SignalAwaiter is awaitable but is not a Task and has no AsTask(). To race it with Task.WhenAny, wrap the await in an async method that returns a Task:

using System.Threading.Tasks;
using Godot;

private async Task<Variant[]> SignalAsTask(GodotObject source, StringName signal)
{
    return await ToSignal(source, signal);
}

public async Task<bool> WaitForSignalWithTimeout(float timeoutSeconds)
{
    // Build a timeout task using Godot's SceneTreeTimer.
    var timer = GetTree().CreateTimer(timeoutSeconds);
    var timeoutTask = SignalAsTask(timer, SceneTreeTimer.SignalName.Timeout);
    var signalTask  = SignalAsTask(this, SignalName.Died);

    var completed = await Task.WhenAny(signalTask, timeoutTask);

    if (completed == signalTask)
    {
        GD.Print("Signal fired before timeout.");
        return true;
    }

    GD.Print("Timed out waiting for signal.");
    return false;
}

Timeout pattern with CancellationTokenSource

using System.Threading;
using System.Threading.Tasks;
using Godot;

public async Task ListenUntilCancelled(CancellationToken token)
{
    while (!token.IsCancellationRequested)
    {
        // ToSignal does not accept a CancellationToken directly;
        // wrap it in a task-race pattern (SignalAsTask is defined above).
        var signalTask  = SignalAsTask(this, SignalName.ItemCollected);
        var cancelTask  = Task.Delay(Timeout.Infinite, token);

        var completed = await Task.WhenAny(signalTask, cancelTask);
        if (completed == cancelTask) break;

        var result = await signalTask;
        HandleItemCollected(result[0].AsString());
    }
}

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts7d3 checks · Risk SAFE
  • Gen Agent Trust Hub7d

    The skill provides safe documentation and code templates for implementing Godot 4.x signals in C#. No malicious patterns, obfuscation, or data exfiltration risks were detected.

  • Socket7d

    No alerts

  • Snyk7d

    Risk: LOW · No issues

Signed by skilld at 426e8ab. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last week

README badge

README badge for jame581/godotprompter/csharp-signals