I have recently decided to start learning Godot after previously having experience with Unity, and am continuing with C# as my primary scripting language. While everything else regarding signals seems to be working, I find myself struggling to emit custom signals, as they are not defined within the SignalName
subclass as the Godot Documentation claims.
Complete script:
using Godot;
using System;
public partial class Icon : Sprite2D
{
[Signal]
public delegate void RotatingToggledEventHandler(bool isRotating);
bool rotating = true;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if(rotating)
{
Rotate((float) delta);
}
}
public override void _Input(InputEvent @event)
{
if(@event.IsActionPressed("ui_accept"))
{
rotating = !rotating;
}
StringName rotatingToggled = "RotatingToggled";
EmitSignal(SignalName.RotatingToggled);
}
}
SignalName
subclass:
public class SignalName : Node2D.SignalName
{
public static readonly StringName FrameChanged;
public static readonly StringName TextureChanged;
public SignalName();
}
The event which is to be triggered by the signal emit:
using Godot;
using System;
public partial class main : Node2D
{
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void OnIconRotatingToggled(bool isRotating)
{
GD.Print("hello there");
if(isRotating)
{
GetNode<Label>("RotatingStatus").Text = "Rotating: active";
}
else
{
GetNode<Label>("RotatingStatus").Text = "Rotating: inactive";
}
}
}
The receiver method is already linked to main.cs
.
Error code is CS0117
.
ADDITIONAL INFO: I am using VS code as my text editor, and have the C#, godot-tools, and C# tools for Godot extensions enabled, and am connected to the GDScript language server. All other facets of scripting seem to be working. For context, I am trying to reconstruct this tutorial in C# to teach myself Godot signals.