public void GetNewPlan() { ClearPlan(); foreach (GoapAction action in AvailableActions) { action.ResetAction(); } List <GoapGoal> orderedGoals = myUtilityEngine.RunUtilityEngine(); UpdateWorldState(); if (orderedGoals.Count > 0) { bool FoundGoalPath = false; int i = 0; while (FoundGoalPath == false) { CurrentGoal = orderedGoals[i]; ActionPlan = myPlanner.GoapPlan(this); if (ActionPlan == null) { // no plan found. ++i; if (i >= orderedGoals.Count) { // end the loop if no path can be found to any goal. FoundGoalPath = true; } } else { // plan found GetNextAction(); FoundGoalPath = true; } } } }