Open Vega-KH opened 6 years ago
I find that this is still an issue in 3.0.6
This depends on #12908 first before a fix can be added for C#.
Just a quick note that I can still see this in 3.2.3 RC6.
Can anyone tell me how to connect the signals to an existing method without it creating a new function or at least how I can work around this ?
@BenBausch You can either connect the signal by code (Object.connect
), or uncheck Make Function in the signal connection dialog.
Alternatively, just cut and paste the code snippet that was erroneously added at the end of the file and move it to the right place.
I don't have a 'Make function' option in the signal connection dialog. Cutting and pasting the code snipped will give me an error because it can not find the function anymore. Thanks for the answer anyway! I will give the gdscript version of godot a shot since it seems less buggy to me :)
I use Rider as external editor. In this case, the code is not generated at all. Even not below the class.
A workaround for the issue of the code not getting generated at all is mentioned in #23208, which is closed now. Basically, method generation for signals doesn't work when using an external editor.
The workaround is to have the built-in Godot editor as the default (Editor > Editor Settings... > Text Editor > External > Use External Editor unchecked). Once you click 'Connect' in the Connect A Signal to a Method dialog box, go to the editor and save the script. Then you can go to your external editor and the method will be there. An issue related to this is that the new method gets created outside of the class. So you have to cut/paste the method into the class.
Following the workaround(s) detailed here does not solve the issue. I can produce the function outside of the class. However, after the function is dragged into the class, the signal fails to call the function.
I personally prefer the editor to do nothing to the C# code file, but save the generated code snip to the clip board. I can then paste the function signature to where I want, or do nothing if the method already exists. Hope there can be some option to enable that.
I'm new to Godot, but I'm still having issues with this in Godot_v3.6-beta4_mono_win64. Not only the signal code is generated outside of the class, but moving it inside causes a false-positive warning for each signal that is re-generated every time I build and cannot be hidden or suppressed in any way. Every signal is working properly and as expected, and I'm slowly driving insane with 32 fake warnings on my screen at all times, and I'll have to migrate that entire part of my code to GDScript just to mitigate that bug. There HAS to be a way to at least suppress this warning in the future...
It should be visible on the screenshot that I've done everything properly (if not, please correct me - the code on the image is inside "public class Main : Control {}")
This is still in an issue in 4.2.1!
This is still in an issue in 4.2.1!
I'm new to Godot, but I'm still having issues with this in Godot_v3.6-beta4_mono_win64. Not only the signal code is generated outside of the class, but moving it inside causes a false-positive warning for each signal that is re-generated every time I build and cannot be hidden or suppressed in any way. Every signal is working properly and as expected, and I'm slowly driving insane with 32 fake warnings on my screen at all times, and I'll have to migrate that entire part of my code to GDScript just to mitigate that bug. There HAS to be a way to at least suppress this warning in the future...
It should be visible on the screenshot that I've done everything properly (if not, please correct me - the code on the image is inside "public class Main : Control {}")
Unbelievably stupid. Weeks lost because of this.
I'm using v4.2.2 Stable (win64 if that matters here) and it's still an issue.
I tried following the 2D game tutorial in Godot's docs until I came to this section of the HUD page. For context, there's a already a function in the project's Main script called NewGame()
(also known as new_game()
in GDScript in case anyone gets confused about the function name in the quote below)
In the Node tab, connect the HUD's start_game signal to the new_game() function of the Main node by clicking the "Pick" button in the "Connect a Signal" window and selecting the new_game() method or type "new_game" below "Receiver Method" in the window. Verify that the green connection icon now appears next to func new_game() in the script.
The HUD script's StartGame()
signal connecting to the Main script's already-existing NewGame()
function is what should happen, but it doesn't. Instead, it just creates a new function altogether.
I apologize for coming across as bitter in this comment, I'm just really frustrated that I keep finding bugs that hurt my workflow. I get Godot's team has GDScript to take care of, but man.
It would be nice to have a switcher to just dont generate the function at all.
It would be nice to have a switcher to just dont generate the function at all.
There used to be one in Godot 3.1 and earlier, but it seems it was removed in 3.2 when redesigning this dialog:
But for the record, this was "fixed" in 4.3 by disabling callback generation for C# in #87952.
I'm keeping this issue open for now as it's a common problem users run into, but we can close it once 4.3 is released.
It's not a perfect solution of course as it still requires users to write the C# callback manually in their class, but it's proving pretty difficult to find a way to insert code in the C# class at the right location, that would support external editors too.
Bugsquad edit: This long standing issue is still valid as of Godot 4.2. It doesn't need further confirmation, but feel free to :+1: the OP to confirm it affects you. Any help welcome to solve this, it's something the .NET team is having difficulty fixing properly, but it's recognized as a major usability issue.
Godot version: 3.0.3 rc1 Mono Build
Issue description: When using the editor to connect a signal to a C# script, the new method declaration is added to the end of the file, and outside of the class. It should instead add the new method just before the final closing brace.
Steps to reproduce:
Example:
This is a low priority issue as the easy workaround is to just move the closing brace of the class, but this creates invalid code and could be confusing.