using Godot;
using System;
public partial class Killzone : Area2D
{
private void OnBodyEntered(Node2D body)
{
GD.Print("Entered killzone");
}
}
The method body_entered has been connected, I’ve named it OnBodyEntered, then manually written the method above (since Godot Engine can’t do that automatically for C#). The issue is that I get a warning: Missing connected method ‘OnBodyEntered’ for signal ‘body_entered’ from node ‘Killzone’ to node ‘Killzone’.
And it’s kind of difficult to progress, since the method is obviously there. In-game the script doesn’t work and nothing appears in output.
Here is the screenshot of the connection in case someone doesn’t believe me.
I suppose you’re talking about a connection made in the editor, right?
I don’t really know how that behaves with C#, tbh. If you find it hard to understand what’s going on when it comes to connection between your C# code and the signals in the Inspector, I’d suggest you do the connection in the code:
public override void _Ready()
{
BodyEntered += OnBodyEntered;
}
Which will ensure a stable behaviour, an easier debugging, and a centralized system.
I know I’m not really answering the question but just suggesting a workaround. Probably someone will come up with a proper answer, but in the meantime, I hope that may help!
Yes, I’m connecting it in the Node menu on the right. I’ve added your piece of code to the class and there is no change - script doesn’t work, and warning is still there. Doing the exact same thing in GDScript works just fine, but I’m more of a C# person, so I want to figure this out so I can keep using it.
Seems strange, I never had any issue with signal connecting in C# like this. Maybe you’re alreay doing some connections inside the editor that could interfere? Have you tried removing anything on Godot side, to leave everything in the C# code?
Also, in Unity, there can be issues with editor connection to private methods. No idea if that could be a thing in Godot too, but for the time it will take, I guess it’s worth trying to change your OnBodyEntered method to public.
I tried removing the connection in the Node menu and the warning is gone, but the script itself doesn’t do anything. Which is indeed strange because as I said, GDScript version works just fine.
It’s what I’ve uploaded in the first post. Including your change:
using Godot;
using System;
public partial class Killzone : Area2D
{
public override void _Ready()
{
BodyEntered += OnBodyEntered;
}
private void OnBodyEntered(Node2D body)
{
GD.Print("Entered killzone");
}
}
Edit
I have partially solved the problem. I have erroneously assigned layer to the player. After fixing it your method does work and does not give any warnings. I appreciate the help a lot.
But I still don’t know why doing it through Nodes doesn’t work. So I will keep the topic up in case someone smart comes in and explains it.
Just kidding, I’m glad it works, at least you can do some progress on your game and care about that signal stuff later on!
You did not mentioned trying to set the method as public, have you tried that? I’m very curious to know if that would be a thing to consider as in Unity or not.
I tried going both private and public. I also tried asking LLMs and they were switching public and private randomly without any reasoning.
And I’m sorry if my previous message seemed inappropriate.
No worry, it didn’t, I was just joking around!
Thanks for the info, that’s good to know. Now let’s indeed wait for someone who may come up with the solution to that problem.
Is the warning shown in the Godot script editor? If yes, the warning might be a bug. It should still work if everything is set up correctly. Can you try again, now that you fixed the layers and masks?
C# support in the built-in editor is very minimal. I recommend to use an external IDE/editor.