protected override IEnumerator Execute() { SetState(NodeState.RUNNING); // Fail action if item is out of reach if (!senses.IsItemInReach(itemToCollect)) { SetState(NodeState.FAILURE); yield break; } actions.CollectItem(itemToCollect); // Check if agent acidentally thinks he picked up item but is not actually in his inventory if (!inventory.HasItem(itemToCollect.name.ToString())) { SetState(NodeState.FAILURE); yield break; } PlayerCache.SetFlagCarriers(itemToCollect); SetState(NodeState.SUCCESS); yield return(null); }