How to await on a function that has an await function within it

Godot 4.3stable

Sorry for the poor title, wasnt sure how to word it.

I have a function that looks like this in my auto battler game.

Original_function()
Await function_1
Await function_2
Await function_3

Function 1 is a function that searches through the players units to see if it has an ability with a specific trigger and calls the ability function on that unit. Function 2 prints “hello”, and function 3 prints “world”. Function 1 uses await when calling the units ability like so.

Await unit.ability_function()

The problem is, that the original function does not wait for the units ability function to finish, it would print hello world at the same time as the units ability function being called.

Im assuming this is intended so i was wondering what a good way to accomplish this goal would be. Essentially how to await on a function called within an awaited function.

Make sure to format your pastes. It looks like you aren’t calling the functions 1 through 3? It should work if your original function actually looks like this.

func original_function() -> void:
    await function_1()
    await function_2()
    await function_3()

await will halt for any awaits within the function as well.

1 Like

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