Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

NavMeshAgent.areaMask returns the wrong mask

Discussion in 'Scripting' started by juiced12, Feb 10, 2021.

  1. juiced12

    juiced12

    Joined:
    Nov 8, 2018
    Posts:
    44
    I have a NavMeshAgent with a component called NavTest.

    I have the NavMeshAgent components areaMask set to "Air" in the inspector.

    Inside my NavTest.cs file I have just the start method with a debug.log call like this

    Code (CSharp):
    1. Debug.Log(GetComponent<NavMeshAgent>().areaMask);
    This results in "8" being printed to the console. This is causing me a bit of a headache as either I'm not getting something here or it's a bug.

    When I Debug with the following line I get my expected result

    Code (CSharp):
    1. Debug.Log(NavMesh.GetAreaFromName("Air"));
    This code returns the correct integer being 3.

    My navigation and component tab looks like this:

    navtest.png

    Is this a bug or is it me not understanding something?
     
  2. juiced12

    juiced12

    Joined:
    Nov 8, 2018
    Posts:
    44
    Replying incase anyone else makes the same mistake.

    SOLVED:

    It appears that NavMeshAgent.areaMask returns a bitfield which means that the return i get of 8 is actually correct. I completely missed that this returned a bitfield and clearly need to look into and understand bitfields .
     
    BroVodo, GrizzlyTank and Cyber-Dog like this.