Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

How to get a callback when NavMesh gets updated?

Discussion in 'AI & Navigation Previews' started by PhilSA, Jul 4, 2017.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I'm making my own nav mesh agent and I need to know when a NavMeshObstacle has carved a hole and updated the navmesh, so that I can recalculate the path.

    Does the NavMesh API provide a callback for this? Or an efficient way to detect a change?
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,977
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Thanks for the answer but that's not exactly what I'm looking for. Basically, what I'd like is to have an event that fires when Unity's navmesh system itself calls "UpdateNavmeshData" (or an equivalent) in the background

    The navmesh system knows when it has to recalculate, based on obstacles being moved, etc.... So it would be a massive waste of performance to have to manually check for re-calculations every frame
     
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,977
    I understand, but unfortunately things are not really made that way. If you want some kind of callback you will need to make one, (which would not waste performance as a callback is event based anyway?), otherwise switch from using the navmesh baker to using the navmeshbuilder api like I said, so you can control all navmesh stuff from code, making this possible as you could then write an event or delegate that wraps up the updatenavmeshdata.

    https://unity3d.com/learn/tutorials/topics/scripting/delegates

    https://unity3d.com/learn/tutorials/topics/scripting/events

     
  5. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    oh wait, I didn't see that part of UpdateNavMeshData:
    This will do the job just fine. I thought it recomputed everything every time.

    Thanks
     
    MadeFromPolygons likes this.
  6. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Sorry for necroing this thread, but how would you go about hooking in a callback in the NavMesh? This seems to me to be the easiest approach if you're not already building around using the NavMeshBuilder, but I can't wrap my head around as to how you'd make that actual callback.
    Thanks in advance!
     
    ina and Ziplock9000 like this.