Search Unity

Tilemap path finding optimization

Discussion in 'Scripting' started by johnsacpe, Sep 8, 2021.

  1. johnsacpe

    johnsacpe

    Joined:
    Jan 25, 2014
    Posts:
    6
    Hi guys,
    I want to make a path finding algorithm (probably A*), but I don't know which method to choose:
    • Just use the GetTile to check if the neighbor tiles are walkable (it would be the easier solution)
    • Implement a 2D int array, which contains every tile ID on the tilemap, and compute from there (it will use more memory, but might be faster)
    Basically, is the GetTile fast enough for path finding?
    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    AStar operates on a graph. If your level's navigation doesn't change, you just need to fabricate that graph at load time (or even at editor time), so performance isn't a huge consideration.

    If the level's navigation changes dynamically (eg, doors opening/closing) then you will need a way to map this information back to the graph that AStar uses for pathfinding.