You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the docs do not provide a way to do this and I have found no way to do this online. Currently, if I emit a signal in C# using the standard EmitSignal(SignalName.SomethingHappened, "args here", ...) and a method that does not match the argument parameters subscribes to this signal, then the signal will silently fail to be delivered anywhere.
The way the system currently works is also prone to bugs as if you decide to change the method's argument types at any point, you will have to manually search for all the places you need to fix this since EmitSignal doesn't do type checks.
I would like a way to emit a signal that uses type checking and will show a syntax error if you don't provide the correct arguments. I've been looking into perhaps binding a method to its arguments and then somehow converting that into a callable when emitting a signal, but I have been unable to figure out if there's a way to do this.
Steps to reproduce
Minimal example of the problem (obviously observer would normally be in different class)
[Signal] public delegate void SomethingHappened(string what);
public override void _Ready()
{
SomethingHappened += OneSomethingHappened;
EmitSignal(SignalName.SomethingHappened, 34); // Wrong param types, fails silently
}
private void OnSomethingHappened(string what)
{
// This will never be called, due to lack of type checking we will not be notified of any compile time errors either
}
Additional note: due to lack of typing, e.g. EmitSignal(SignalName.SomethingHappened, null); will also never call OnSomethingHappened(null). You'll need to do EmitSignal(SignalName.SomethingHappened, null as string);, which is very confusing, especially for beginners.
Minimal reproduction project
View steps to reproduce
The text was updated successfully, but these errors were encountered:
Godot version
v4.1.1.stable.mono.official [bd6af8e]
System information
Godot v4.1.1.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 31.0.15.3623) - Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz (16 Threads)
Issue description
Currently the docs do not provide a way to do this and I have found no way to do this online. Currently, if I emit a signal in C# using the standard
EmitSignal(SignalName.SomethingHappened, "args here", ...)
and a method that does not match the argument parameters subscribes to this signal, then the signal will silently fail to be delivered anywhere.The way the system currently works is also prone to bugs as if you decide to change the method's argument types at any point, you will have to manually search for all the places you need to fix this since EmitSignal doesn't do type checks.
I would like a way to emit a signal that uses type checking and will show a syntax error if you don't provide the correct arguments. I've been looking into perhaps binding a method to its arguments and then somehow converting that into a callable when emitting a signal, but I have been unable to figure out if there's a way to do this.
Steps to reproduce
Minimal example of the problem (obviously observer would normally be in different class)
Additional note: due to lack of typing, e.g.
EmitSignal(SignalName.SomethingHappened, null);
will also never call OnSomethingHappened(null). You'll need to doEmitSignal(SignalName.SomethingHappened, null as string);
, which is very confusing, especially for beginners.Minimal reproduction project
View steps to reproduce
The text was updated successfully, but these errors were encountered: