Wait for parent node to be Ready in C#
Asked Answered
H

5

0

How can I achieve this in C#. I need to wait until the parent node has finished his initialization.

yield(owner, "ready")

Headstream answered 22/10, 2022 at 16:13 Comment(0)
R
0

Instead of yielding, connect the ready signal from parent to child

Reamer answered 22/10, 2022 at 21:3 Comment(0)
H
0

Thanks will try it that way.

Do you know is it generally possible to "await" things with C# in Godot? So using Task, IEnumarators and async operations?

Headstream answered 23/10, 2022 at 9:48 Comment(0)
C
0

Headstream

Yes, you can use Node.ToSignal(), like this:

await ToSignal(GetTree(), "idle_frame");
Cupel answered 8/11, 2022 at 16:34 Comment(0)
C
0

Reamer

This can be achieved with:

await ToSignal(GetParent(), "ready");
Cupel answered 8/11, 2022 at 16:38 Comment(0)
H
1

Or better yet:
await ToSignal(Owner, SignalName.Ready);

By using SignalName you avoid having to use string literals.
And Owner might be better than parent, depending on what's happening in your code.
Also, don't forget that the method this line is in will have to be set as async in order to use await.

Hesione answered 12/1 at 10:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.