Description
Signals in Godot-rust are like 90% perfect to being perfect.
There’s already been lots of prior work done on async signals, but they are all around connecting them and receiving them.
There doesn’t seem to be much work done on EMITTING signals async.
The biggest problem I can think of is that usually &self is not send/sync, since Gd isn’t suited for multi threading. As such, there’s basically no way to spawn an async task within a function that emits a signal.
For example, this does not work (assume I am using https://github.com/2-3-5-41/godot_tokio )
impl Monster {
// Can be invoked by other game systems.
pub fn deal_damage(&mut self, amount: i32) {
self.hitpoints -= amount;
AsyncRuntime::spawn( async {
self.signals().damage_taken().emit(amount);
});
}
}
I’ll be honest - not totally sure how to fix this. Maybe allow to clone a signal?
For the record: the current way to do this is to run your async tasks in the background, and poll on process() using channels. Once you receive something in the channel, you can emit a signal to let the other nodes that something happened. This is FINE, but it’s unwieldy and doesn’t feel very Godot.