0 votes
signal test()

# func a():
#   emit_signal("test")

func b():
    c("test")

func c(s):
    emit_signal(s)

The signal 'test' is declared but never emitted.

I have a few signals I wanted to route through one function, because a lot of the code is the same, and I can just pass in the signal, but gives me warnings... :(

Thanks.

in Engine by (1,863 points)

2 Answers

+1 vote
Best answer

In the script you provided this is true because you never actually call b(), e.g.:

func _ready():
    b()

However, even if you do this, the warning won't be gone. But it will work:

signal test()

func _ready():
    connect("test", self, "_on_test")
    b()

func b():
    c("test")

func c(s):
    emit_signal(s)

func _on_test():
    print("It works")

But why the warning then? Because the GDScript parser won't recognize that you actually do emit the signal, albeit using a variable argument. Try this:

func c(s):
    match s:
        "test":
            emit_signal("test")

If that's no option for you, you can also disable the warning under Project > Project Settings... > Debug > Gdscript > Unused Signal or add an exception with:

#warning-ignore:unused_signal
signal test()
by (10,421 points)
selected by

Hmmm... Beat me to it... ;^)

+1 vote

So, what's the question exactly?

I assume because of the indirection involved with your signal setup, it's not being detected by the engine, which generates a warning.

And, it is just a warning. You can do a few things here...

  • Just don't pay any attention to it.
  • Tell Godot to ignore that single instance of the warning by clicking the small yellow warning symbol in the status bar of the code editor and choosing the provided ignore link.
  • Ignore all such warnings via Project | Project Settings | Debug | Gdscript | Unused signal

However, I'd recommend that you don't blindly ignore warnings (without understanding why your ignoring them) as, generally, they are there to assist you...

by (12,286 points)
edited by
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 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 webmaster@godotengine.org with your username.