Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type checking for C# signal emitting #83982

Closed
mickeyordog opened this issue Oct 26, 2023 · 3 comments
Closed

Type checking for C# signal emitting #83982

mickeyordog opened this issue Oct 26, 2023 · 3 comments

Comments

@mickeyordog
Copy link
Contributor

mickeyordog commented Oct 26, 2023

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)

[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

@AThousandShips
Copy link
Member

This is a feature, so please open a proposal as this is for bugs, not missing features

@Thomas-X
Copy link

Resolved by #68233

@akien-mga
Copy link
Member

This seems to be this existing proposal: godotengine/godot-proposals#7891

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants