This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+2 votes

Hi All. I constantly see multiple instances of this warning in the debugger and it annoys the hell out of me...

In _ready(), I'm connecting several signals to functions in a singleton script. For each of these connections I get a warning like this up front. Indeed, the signals aren't emitted until something happens in the game that will emit them but... so what?

Do I need to move the connect's to the functions that emit the signals?

in Engine by (516 points)

6 Answers

+2 votes
Best answer


This warning has nothing to do with when the signal is emitted. It means that the function "connect" returns something, more precisely it returns a value of the Error enum (you can go check the details Here ), and you are not using that value.

I'll guess that your code is something like this:

func _ready():
      #rest of the function

Thus the returned error value is discarded and the warning raised.

What you can do is use the error for debug checks or something similar or you can ignore the warning by clicking in the warning triangle and selecting ignore warning.

by (73 points)
selected by

Can i somehow 'use' the enum value to hash both the debug warning and the 'ignored warning' comment that shows up in the code when i ignore (which is no less irritating if im being honest)..?

If you create a variable just for the return value maybe the editor will warn you that you created a variable and then never used it.

If those warnings really annoy you that much you can disable them here:
Project Settings → Debug → GDScript → Warnings
But they will also disappear with other functions.

Do what makes you work more comfortable.

So, can I just as safely ignore it ?

If you do not want to use the returned value for debug reasons then yes you can ignore it.

+2 votes

A simple fix I found is to set the signal equal to an arbitrary variable.

var _random_var = connect("signal", self, "signal_function")

Hope this helps.

by (18 points)

Hi there... I use this fix aswell, but I really wanted to understand what it means exactly and if it is the right way to do it...

connect() will complain that value is never used
var random_var = connect() will complain that the variable is never used
and finally,
var _random_var = connect() will stop the warning

but what happened there? this fix also works for ternary if's... what am I storing in a variable and howcome a dash tell its ok that is never used... I get a little confused about the right way to respond to this issue

In this case, the underscore is just there to tell the compiler "Hey, I don't intend to use this variable."
I believe this is called a Dummy Variable or Discard.

Godot actually has some warnings that recommend doing this, in particular:
The argument 'delta' is never used in the function 'physicsprocess'. If this is intended, prefix it with an underscore: '_delta'

So it's definitely fine to continue doing this, and I personally prefer it over the "Ignore warning" button.

+2 votes

connect() will give you a value never used warning

var random_var = connect() will give you a variable never used warning

var _random_var = connect() will stop the warning and the variable/value discarted

BUT, this will store the value in a variable and use that variable to print an error if it happens and will also stop the warning, while not stopping errors to be shown.
Error code 0 means no errors

var error_code = connect()
if error_code != 0:
    print("ERROR: ", error_code)
by (375 points)

This will also happen with some Ternary IF's for some reason, same "fix" applies.

var _run ="running_suit") if PlayerData.has_suit else"running")

Wish I could understand this better aswell

because ternaries were never meant for calling functions, they are for getting one value or another

var estimate = "good" if score > 5 else "bad"

if you want to call one function or another use if-else

if PlayerData.has_suit:"running_suit")
+5 votes

Disable the warning for this one instance:

func myfunc():
    foo = 'bar'
    # warning-ignore:return_value_discarded

More about warnings and disabling them here:

by (28 points)

I like this solution as it documents the code and tells the reader of the code that you made a conscious decision to suppress and are aware a return value normally exists.

0 votes

This question is old, but I ran across it while searching for info on the same problem because I wanted to see if there was a standard way of handling this.

It doesn't look there is.

I found the best way is to wrap them in an assert. It's an inline solution that gets rid of the warning and will let you know if there is a problem with your signal connection which you probably want to know about anyways.


assert(get_tree().connect("peer_connected", self, "_peer_connected") == 0)

Creating vars for each signal and then leaving them to be cleaned up or checking their values is a lot of pointless extra code.

Ignoring warnings is almost always a bad idea.

by (15 points)

Don't do this!
I found out the hard way that asserts are removed in release builds which will break your game.

From the docs:

The assert keyword can be used to check conditions in debug builds. These assertions are ignored in non-debug builds. This means that the expression passed as argument won't be evaluated in a project exported in release mode. Due to this, assertions must not contain expressions that have side effects. Otherwise, the behavior of the script would vary depending on whether the project is run in a debug build.


Thanks for the clarification @jibby

0 votes

If you want to get an error when a connect call fails, you can make a validate module with a static function that I can reuse anywhere connect (or other Godot API functions) shouldn't fail:

static func ok(err):
    assert(err == OK)

const validate = preload("res://code/util/")
func _ready():
        validate.ok(btn.connect("pressed", self, "_on_btn_pressed"))

Similar to @kismet's idea of using assert except this function call won't get removed in builds.

by (154 points)
edited by

Looks really cumbersome as you can just use an object's call function"connect", "pressed", self, "_on_btn_pressed")

Nice one-liner that also shows error if something goes wrong

@Wakatta That eliminates the lint warning, but you won't get an error when connection fails.

Make sure you don't have warnings disabled.
Because it reports connection failures just fine with a warning

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.