migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.06k stars 65 forks source link

Unable to use `await` for `Timer.timeout` signal #403

Closed tishin closed 6 months ago

tishin commented 6 months ago

A simplified node example:

@Godot
class TimerNode: Node {

    let timer = Timer()

    override func _ready() {
        addChild(node: timer)

        timer.start()
        GD.print("started")

        Task {
            await timer.timeout.emitted
            GD.print("emitted")
        }
    }

}

Awaiting for timeout throws an error:

ERROR: Caller thread can't call this function in this node (/root/Timer/@Timer@2). Use call_deferred() or call_thread_group() instead.
at: connect (scene/main/node.cpp:3706)
Warning, error connecting to signal timeout: errInvalidParameter

And the second print does not happen.