Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

[Solved] NavMeshBuildSettings for agent type ID: -1 wasn't found

Discussion in 'AI & Navigation Previews' started by Deleted User, Nov 9, 2016.

  1. Deleted User

    Deleted User

    Guest

    I have a NavMeshSurface component with a baked NavMesh,
    and there is an agent in the room.

    the ONLY "agent type" in my project is the default Humanoid

    my agent's behavior code works as intended, the agent wanders around the room all according to plan, but the
    Console is throwing the following error every frame:



    NavMeshBuildSettings for agent type ID: -1 wasn't found
    UnityEngine.AI.NavMesh:Raycast(Vector3, Vector3, NavMeshHit&, Int32)
    State_Wander:NavMeshRaycast() (at Assets/05 Scripts/AI/State_Wander.cs:127)
    State_Wander:Think() (at Assets/05 Scripts/AI/State_Wander.cs:108)
    State_Wander:Think() (at Assets/05 Scripts/AI/State_Wander.cs:103)
    State_Wander:Rest() (at Assets/05 Scripts/AI/State_Wander.cs:65)
    State_Wander:UpdateStatus() (at Assets/05 Scripts/AI/State_Wander.cs:35)
    Behavior_WanderBotLinear:Update() (at Assets/05 Scripts/AI/Behavior_WanderBotLinear.cs:36)


    this is the code for my Agent's Behavior

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5.  
    6. public class State_Wander : IActStatus_WanderBot {
    7.  
    8.     private readonly Behavior_WanderBotLinear behaviorObj;
    9.  
    10.     public State_Wander (Behavior_WanderBotLinear actorPattern) {
    11.         behaviorObj = actorPattern;
    12.     }
    13.  
    14.     int currentActionFlag = 0;  // 0 = initial, 1 = hasThought, 2 = timeExpired
    15.     float restTimer;
    16.     float restTime;
    17.  
    18.     int wanderDirectionFlag = 0;  //0 = null , 1 = North, 2 = East, 3 = South, 4 = West.
    19.     float wanderDistance = 0;
    20.     Vector3 originalPos;
    21.     Vector3 intendedPos;
    22.     Vector3 destinationPos;
    23.  
    24.  
    25.     #region IActorStatus_Root implementation
    26.  
    27.     public void UpdateStatus()
    28.     {
    29.         if (behaviorObj.navMeshAgent.remainingDistance <= behaviorObj.navMeshAgent.stoppingDistance) {
    30.             if (!behaviorObj.navMeshAgent.hasPath || Mathf.Abs ( behaviorObj.navMeshAgent.velocity.sqrMagnitude) < float.Epsilon) {
    31.                 currentActionFlag = 0;
    32.             }
    33.         }
    34.         if(currentActionFlag == 0 || currentActionFlag == 1) {
    35.             Rest();
    36.         }
    37.     }
    38.  
    39.     public void GoalAchieved()
    40.     {
    41.         throw new System.NotImplementedException();
    42.     }
    43.  
    44.     public void OnTriggerEnter(Collider other)
    45.     {
    46.  
    47.     }
    48.     #endregion
    49.     #region IActor_WanderBot implementation
    50.  
    51.     public void ToWanderState()
    52.     {
    53.         throw new System.NotImplementedException();
    54.     }
    55.  
    56.     public void ToReactionState()
    57.     {
    58.         throw new System.NotImplementedException();
    59.     }
    60.     #endregion
    61.  
    62.     void Rest() {
    63.         behaviorObj.navMeshAgent.Stop();
    64.         if(currentActionFlag == 0) {
    65.             Think();
    66.         }
    67.         restTimer += Time.deltaTime;
    68.  
    69.         if(restTimer >= restTime) {
    70.             restTimer = 0;
    71.             currentActionFlag = 2;
    72.             Wander();
    73.         }
    74.     }
    75.  
    76.     void Think() {
    77.         currentActionFlag = 1;
    78.         restTime = Random.Range(behaviorObj.minRestTime, behaviorObj.maxRestTime);
    79.         wanderDirectionFlag = Random.Range(1,5);
    80.         wanderDistance = Random.Range(behaviorObj.minWanderDistance, behaviorObj.maxWanderDistance);
    81.         originalPos = behaviorObj.theActorGO.transform.position;
    82.         switch (wanderDirectionFlag) {
    83.             case 1:
    84.                 intendedPos = new Vector3(originalPos.x, originalPos.y, originalPos.z + wanderDistance);
    85.                 destinationPos = NavMeshRaycast();
    86.                 if(destinationPos.z - behaviorObj.theActorGO.transform.position.z <= behaviorObj.minWanderDistance / 2) {
    87.                     Think();
    88.                 }
    89.                 break;
    90.             case 2:
    91.                 intendedPos = new Vector3(originalPos.x + wanderDistance, originalPos.y, originalPos.z);
    92.                 destinationPos = NavMeshRaycast();
    93.                 if(destinationPos.x - behaviorObj.theActorGO.transform.position.x <= behaviorObj.minWanderDistance / 2) {
    94.                     Think();
    95.                 }
    96.                 break;
    97.             case 3:
    98.                 intendedPos = new Vector3(originalPos.x, originalPos.y, originalPos.z - wanderDistance);
    99.                 destinationPos = NavMeshRaycast();
    100.                 if(behaviorObj.theActorGO.transform.position.z - destinationPos.z <= behaviorObj.minWanderDistance / 2) {
    101.                     Think();
    102.                 }
    103.                 break;
    104.             case 4:
    105.                 intendedPos = new Vector3(originalPos.x - wanderDistance, originalPos.y, originalPos.z);
    106.                 destinationPos = NavMeshRaycast();
    107.                 if(behaviorObj.theActorGO.transform.position.x - destinationPos.x <= behaviorObj.minWanderDistance / 2) {
    108.                     Think();
    109.                 }
    110.                 break;
    111.         }
    112.        // if(NavMesh.FindClosestEdge(behaviorObj.theActorGO.transform.position, out hit, NavMesh.AllAreas)) {
    113.        // behaviorObj.theActorGO.transform.LookAt(intendedPos);
    114.     }
    115.  
    116.     void Wander() {
    117.         behaviorObj.navMeshAgent.SetDestination(destinationPos);
    118.         behaviorObj.navMeshAgent.Resume();
    119.     }
    120.  
    121.     Vector3 NavMeshRaycast() {
    122.         NavMeshHit hit;
    123.         bool obstructed;
    124.  
    125.         obstructed = NavMesh.Raycast(behaviorObj.theActorGO.transform.position, intendedPos, out hit, NavMesh.AllAreas);
    126.         if(obstructed == true) {
    127.             destinationPos = hit.position;
    128.         }
    129.         else {
    130.             destinationPos = intendedPos;
    131.         }
    132.         return destinationPos;
    133.     }
    134.  
    135.  
    136. }
    137.  
     
    Last edited by a moderator: Nov 9, 2016
  2. Deleted User

    Deleted User

    Guest

    oh durr
    iam using the NavMesh.Raycast from the Unity Scripting docs online, not from the lowlevel .pdf


    the new one wants a NavMeshQueryFilter

    Code (CSharp):
    1. bool NavMesh.Raycast (Vector3 sourcePosition, Vector3 targetPosition, out NavMeshHit
    2. hit, NavMeshQueryFilter filter)
     
unityunity