Return a Signal like return from a method

Godot Version

4.2

Question

I would like to know how to return a signal awaitable from a method or function
For instance.

Node1
----code
----code
await node2.operation()
----code
----code

Node2

signal endOperation

func operation() → Signal:
–code
–code
endOperation.emit()
return endOperation

I want to create something similar to

get_tree().create_timer(0.01).timeout

This function return a signal. how to do it.

The example you gave does not make much sense as you are returning the signal after being emitted so it probably block the execution of the function that’s awaiting until the signal is emitted again.

The SceneTree.create_timer() function does not return a signal. It returns a SceneTreeTimer object which has a timeout signal.

It’d be better if you explain what you want to achieve exactly with an example.

1 Like

Thanks. But I was reading a little more and the solution was something like this.
Node2

signal endOperation

func operation() → Signal:
–code
–code

(func(): endOperation.emit()).call_deferred()

return endOperation

But I´m really interested to create a code like this function to return a signal

get_tree().create_timer(0.01).timeout
how to create this interface “timeout” because the timer return this one.

Again, please explain precisely what you want to achieve with a clear example because the solution you found does not make any sense. Why would you await until the end of the frame to continue executing whatever code you had after awaiting the operation() method?

And, as I said before, get_tree().create_timer(0.1).timeout does not return a signal. SceneTree.create_timer() returns an object which has the timeout signal.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.