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

It is not possible to handle player input because the tree cannot wait for some action while execute other in parallel #39

Closed
mwss1996 opened this issue Nov 22, 2022 · 1 comment

Comments

@mwss1996
Copy link

mwss1996 commented Nov 22, 2022

I was trying to build a character controller script using NPBehave.
I have a blackboard with a key called "isMovePressed" that turns true or false depending on player input.
So i used the BlackboardCondition to set the animator key to true of false if the "isMovePressed" value is updated.

The problem is that the Parallel node only keeps executing its children if a SUCCESS or FAILED status is returned by the children,
if i return PROGRESS the other actions will keep waiting and the rest of the tree will not work.

But if i return SUCCESS or FAILED the action DoStop() will never be called on the BlackboardCondition class and is not possible to set the animator "isWalking" boolean back to false when the condition fails.

So based on this i believe it is not possible to handle player input on this library, because the tree cannot wait for some action while execute other in parallel.

My question is if this is right or do i miss something?

return new Root(
    blackboard,
    new Parallel(
        Parallel.Policy.ALL,
        Parallel.Policy.ALL,
        new BlackboardCondition(
            "isMovePressed",
            Operator.IS_EQUAL,
            true,
            Stops.SELF,
            new Action(
                (abort) =>
                {
                    if (abort)
                    {
                        animator.SetBool("isWalking", false);
                        return Action.Result.SUCCESS;
                    }
                    animator.SetBool("isWalking", true);
                    return Action.Result.PROGRESS;
                }
            )
        ),
        new Action(() => Debug.Log("ONLY RUN WHEN THE FIRST RETURN SUCCESS OR FAILURE;"))
    )
);
@meniku
Copy link
Owner

meniku commented Nov 23, 2022

The Parallel Node doesn't restart finished children. Out of my head I'm not sure if such an option would be a good addition to the library or not.

However I think you could use one of the following workarounds:

  1. wrap the second action inside a Loop node
  2. wrap the first action inside an Observer which updates the animation graph and make the action immediately return SUCCESS

I hope that helps

@meniku meniku closed this as completed Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants