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. Dismiss Notice

*SOLVED* agent.currentOffMeshLinkData.offMeshLink is NULL

Discussion in 'Navigation' started by mistergreen2016, Jun 29, 2019.

  1. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    Hey,
    I'm trying to do different animation based on different area type of the offMeshLink.

    So I do a simple
    Code (CSharp):
    1.  if (agent.isOnOffMeshLink)
    2.             Debug.Log("start link: " + agent.currentOffMeshLinkData.offMeshLink.area )
    It's coming up
    NullReferenceException: Object reference not set to an instance of an object
    because offMeshLink is null. The agent.isOnOffMeshLink is true. Is this a bug? I'm using 2018.3
     
    Last edited: Jun 29, 2019
  2. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    I found the answer.
    It's not intuitive from the code but this is how it was set up.
    Code (CSharp):
    1.         if (agent.isOnOffMeshLink) {
    2.             NavMeshLink link = (NavMeshLink)agent.navMeshOwner;
    3.  
    4.             Debug.Log("start link: " + link.area);
    5. }
     
    WalnutBat likes this.
  3. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    65
    Many tanks and thanks, my friend.
     
  4. sayginkarahan

    sayginkarahan

    Joined:
    Jan 23, 2015
    Posts:
    49
    Thank you so much ;)