Hello all, I'm following the Heartbeast ARPG tutorial and I'm having trouble setting up signals for a Autoload Singleton. The way I did it following the tutorial is that we first had a "Stats" node with a script Stats.cs attached to it, and then we created an inherited scene "PlayerStats" inheriting from the Stats node. This scene is attached to the same Stats.cs script, and then I added the PlayerStats to the project's globals as seen in the image.
Now I'm trying to set up a signal for the PlayerStats for when the health changes, notifying my UI (HealthUI). Here's what my code looks like for Stats.cs
using Godot;
using System;
public partial class Stats : Node
{
public static Stats Instance { get; private set; }
[Export]
public int MaxHealth = 1;
private int _currentHealth;
[Signal]
public delegate void NoHealthEventHandler();
[Signal]
public delegate void HealthChangedEventHandler(int value);
public int Health
{
get => _currentHealth;
set
{
_currentHealth = value;
EmitSignal(SignalName.HealthChanged, _currentHealth);
if (_currentHealth <= 0)
{
EmitSignal(SignalName.NoHealth);
}
}
}
public override void _Ready()
{
Instance = this;
_currentHealth = MaxHealth;
}
}