Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Coroutines in BT Tasks #266

Open
RoyAwesome opened this issue Dec 30, 2024 · 0 comments
Open

Add Support for Coroutines in BT Tasks #266

RoyAwesome opened this issue Dec 30, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@RoyAwesome
Copy link

RoyAwesome commented Dec 30, 2024

Problem statement

Lets say you have a pretty simple "Move to target" task

pseudocode-y

func _tick(delta: float) -> Status:
    var unit = agent as UnitNode
    unit.NavAgent.target_position = blackboard.get_var(_move_target)
    await unit.NavAgent.navigation_finished
    return SUCCESS

This doesn't work. The BT Task is expecting _tick to return a Status.Running to continue execution, and _tick doesn't return that at all (it's a coroutine now).

Proposed solution

This example probably should work somehow. If you can get the function state object, you can probably just check if _tick returned that, and if you do have that just store it off in the BTTask and check it every frame if it's finished. If the coro hasn't finished, return RUNNING.

I'm a bit of a godot extension noob, so I don't actually know if checking if _tick has become a coro is possible in gdext. If it's not, this issue can be used to show there is real world support for things like that.

Alternatives

The workaround here is easy if you are awaiting a signal, as you can just bind a lambda to it's signal and mutate some bool and emulate the coroutine that way. However, if you aren't awaiting a signal (but instead a generic coroutine), you cannot do this, and there is no workaround in gdscript, as you cannot acquire the function state object.

@RoyAwesome RoyAwesome added the enhancement New feature or request label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant