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

Question about Corners

Discussion in 'Navigation' started by Multithreaded_Games, Mar 22, 2018.

  1. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Hi all!

    I'm using CalculatePath to return a new path and then accessing the corners variable there in order to see if any of the 'waypoints' are outside of a designated movement radius.

    I need this to be faster than it currently is (I'm calling it a bunch of times per frame) and after looking at the profiler, it looks like CalculateCornersInternal is being called (or something) whenever I access corners. That begs the question, then, what is CalculatePath doing exactly? The NavMeshPath only has a few fields--is it not itself filling the corners when you call CalculatePath? Is there a way to 'cache' these corners at the same time that CalculatePath is being called?

    Thanks!
     
  2. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    707
  3. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Thanks for the answer. My question is more related to, 'Why does Unity incur an extra penalty when I access the corners' array, even though I've already calculated the path (and presumably, the corners) using the CalculatePath function beforehand?

    What is a NavMeshPath, except a collection of corners (points)? I'm somewhat confused as to how the corners aren't already known to the path returned by CalculatePath.

    I suspect this would require someone from Unity to chime in as we can't see the internals of it.
     
    JBR-games likes this.
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    You can actually to some extent, as it's based on https://github.com/recastnavigation/recastnavigation.

    navmesh pathfinding has multiple steps it's just how it works. You have tiles and polygons within the tile and the path within a polygon and finally string pulling, or straightening the path.