Godot: Signal connection "Make function" option does not work on C# when using an external editor

Created on 21 Oct 2018  路  25Comments  路  Source: godotengine/godot


Bugsquad edit: This issue has been confirmed several times already. Please don't comment to confirm that this issue still occurs.


Godot version:
Godot Engine v3.0.6.stable.mono.official.8314054

OS/device including version:
Windows 10, Nvidia GT710

Issue description:
The C# function that is supposed to receive the signal is not created, hence never called.

Steps to reproduce:

  • Create a main node
  • Create a subnode "HTTPRequest"
  • Click HTTPRequest > Node > Signals
  • Choose request_completed
  • Click "Connect ..."
  • Choose the main node
  • Enable "Make Function"
  • Leave defaults
  • Click "Connect"

Note

I'm new to Godot so maybe I did something wrong there, but from my understanding, using "connect" to bind the signal to a C# script should create the function automatically and be called when the event is triggered. Should it be done manually when using C# ? (Although I saw some videos showing it was generated automatically, even in C#)

archived bug editor

All 25 comments

Were you able to get it working with GDScript (to know if it's a C#-specific issue)?

Yes, it worked properly when using GDScript

It should be created, but it should be appended to the end of the file rather than to the class. If that's the case here, then this would be a duplicate of #18721

Okay, it finally worked.

It was linked to the use of Visual Studio Code. Switching to the embedded Godot text editor made it work properly. This functionality seems broken when using VSCode.

Side note : leaving the added function at the end of the file throws an error : "A namespace cannot directly contain members such as fields or methods".

Code before adding signal function :

using Godot;
using System;
using System.Linq;
using BoomCraft.Model;
using BoomCraft.Services;
using BoomCraft.Utils;
using Newtonsoft.Json;

public class MainSceneHandler : Node
{
    private MapService _mapService = new MapService();
    public override async void _Ready()
    {
        ...
    }
}

Code after adding signal function :

using Godot;
using System;
using System.Linq;
using BoomCraft.Model;
using BoomCraft.Services;
using BoomCraft.Utils;
using Newtonsoft.Json;

public class MainSceneHandler : Node
{
    private MapService _mapService = new MapService();
    public override async void _Ready()
    {
        ...
    }
}

private void _on_HTTPRequest_request_completed(int result, int response_code, string[] headers, byte[] body) // <------ Syntax error
{
    // Replace with function body   
}

It was linked to the use of Visual Studio Code. Switching to the embedded Godot text editor made it work properly. This functionality seems broken when using VSCode.

This is still an issue. Is it possible to fix?

This issue should be renamed to clarify this issue happens when using external editors. The probably happens with GDScript as well. Can anyone confirm?

This all really boils down to #12908

Yes it "works" with the built-in editor, but it simply appends the code, which is a problem for C# since it ends up outside the class.

As far I can tell #12908 is about function being placed at the wrong spot? When using VSCode function is not generated at all.

18721 is about the function being placed outside the class. #12908 is about changing the script language API to make it possible to control the way the method is added, but it does not include actually implementing it for C#, so it's more like a first step towards fixing #18721.

This issue is about the new method not appearing in the file that is open in the external editor.

This is still valid in 3.2 as seen by @fasterthanlime on stream.

It makes it pretty difficult to handle signals with a lot of parameters like HTTPRequest ones. Would be great to have a fix soon-ish that could be backported to 3.2.x.

Can confirm this is still happening I ran into it today using VS Code as an external editor. Would like to have this fixed.

This issue just occured for me as well. I'm going through Godot's 'Your First Game' walkthrough using C# and Rider as the external editor. The connected methods are not being created. It works perfectly when using the integrated editor.

I've tried using VSCode, same issue.

Can confirm. VSCode editor, method is not being created when connect signal. Have to do write it by myself all the time.

Can also Confirm VSCode editor with the latest v3.2.2.rc4 not creating void when connecting a signal from godot editor. It opens the script, so I can just write the void myself, though it would be nice for it to work as it does in GDScript.

This is still an issue with Godot v3.2.2 and godot-tools v1.1.1 for VSCode

We don't really need more confirmations at this point, we've had enough :slightly_smiling_face:

This will be fixed when someone who knows how to fix this opens a pull request.

I'm using latest Rider and Godot 3.2.2, same issue

@Calinou I can help with PR if you can help with point where I can start to look to fix this issue.

@Mirodil I don't know where exactly this should be fixed, but it probably has to do with saving the script automatically when using Make Function so the external editor can reload it. (If the script isn't saved yet, there's no way the external editor can pick up changes.)

This is actually a major workflow problem if you want to develop in C# while using an external editor like VScode. Someone mentioned this problem does not happen with gdscript, so whatever the bridge is between gdscript and external editors should be able to be ported over to C# I'm guessing ? I wish I had the time to figure it out :(

@kendinitto I think the issue has more to do with using an external editor than C# in itself.

A simple fix would be to save the file automatically when Godot creates the function in its built-in script editor. This way, the external editor will reload the file (if it supports automatic file reloading) and show the newly created function.

However, this is problematic if you've made unsaved changes in the external editor, since you'll see a "conflict prompt" in this case (as the file has been modified externally, yet you had unsaved changes). This could be alleviated by enabling the "save on focus loss" behavior in your external editor.

Too bad Godot cant display a copy of the function somewhere other than the built in editor so you can copy and paste it into the external editor. When I set Godot to use an external editor the built in editor does not work at all its just a black screen. The main issue is when it comes to c# I am not always sure what the proper structure of the function is supposed to be as it seems to be different based on the type of signal. Sometimes it has object variable in there and sometimes not for example.

For what it is worth I noticed if you go to editor settings and under mono settings select an external editor, in my case VS code, but under text editors > external do not turn this on, what this does is it will use the external editor to edit while leaving the internal editor turned on as well. If you save in either editor the other one gets updated. So if you create a signal it will insert it into the internal editor and you just save it (cntrl-s) and the external editor will be updated with the new function code. Its not perfect but it seems to be a workflow that can work since the only time you need to deal with the internal editor is if you create a signal.

Would be nice if this could get fixed, I'm having the same problem with Rider

Duplicate of https://github.com/godotengine/godot/issues/41283. This issue isn't specific to C# usage; it's specific to external editors.

Was this page helpful?
0 / 5 - 0 ratings