Search Unity

Pluggable AI Session - Problem with overwriting eachother

Discussion in 'Community Learning & Teaching' started by SuperMops, Feb 7, 2018.

  1. SuperMops

    SuperMops

    Joined:
    Feb 7, 2018
    Posts:
    28
    Hi,

    I just tried to adopt the cool system from the Pluggable AI live training session
    https://unity3d.com/de/learn/tutori...nite-state-ai-delegate-pattern?playlist=17105

    into my project, but I have a problem when i use several transitions on one object like here:

    SeveralTransitionExample.png

    Some agent basically has to look for resources and collect them when he finds some, which works fine.
    But there is a second condition, which is that once he has 4 resources he should stop collecting them, but
    trade them at a trade-post.
    example.png

    But as soon as I put in the other transition then it's FALSE condition keeps overriding the true condition
    of the first transition and I end up in the wrong state, which makes sense, when you think about it, but isn't the system created to be used on more than one transition?


    So here's the peace of code that goes over the transitions:
    Code (CSharp):
    1. private void CheckTransitions(StateController controller)
    2.     {
    3.         for (int i = 0; i < transitions.Length; i++)
    4.         {
    5.             bool decisionSucceeded = transitions [i].decision.Decide (controller);
    6.  
    7.             if (decisionSucceeded) {
    8.                 controller.TransitionToState (transitions [i].trueState);
    9.             } else
    10.             {
    11.                 controller.TransitionToState (transitions [i].falseState);
    12.             }
    13.         }
    14.     }
    (copied from the original live session)

    I guess when you don't know the session it's not so easy to see the problem, but maybe
    someone has tried to implement this pattern and had similar issues.