Search Unity

  1. Unity 2019.2 is now released.
    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:
    120
    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:
    120
    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. }
     
  3. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    33
    Many tanks and thanks, my friend.