I am trying to implement behaviour trees in untiy and right now i am using a Tick() function for each Node/Composite/Action
What I want to do :
- Begin the for loop itereating in the list of nodes
- Start the tick function on the current node
- Wait until the node tick returned Failed/Success
- Go to the next node and continue to go to step 1
What i want to do is in a sequence for example, pause the execution of the execute function (line 29) until the node
has reached a Failed/Success Status. I am trying to acomplish this using a coroutine
IEnumerator Recursive(Node nod)
{
while (true)
{
Debug.Log(nod + "is running");
Status status = nod.Tick();
Debug.Log(Time.time + " " + status);
if (status == Status.Running)
{
Debug.Log("start coroutine at : " + Time.time);
yield return new WaitForSeconds(0.2f);
Debug.Log("Comtinue coroutine at : " + Time.time);
}
else
{
Debug.Log("has finished coroutine");
nodeStat = status;
break;
}
}
}
protected override Status Execute()
{
foreach(Node nod in ListaNoduri)
{
GameManager.Instance.StartCoroutine(Recursive(nod));
Debug.Assert(nodeStat != Status.None);
if (nodeStat == Status.Failure)
return Status.Failure;
}
return Status.Success;
}
the problem is that the assertion is true, the nodeStat var is None because the coroutine does not finish