Support Forum

A* Pathfinding in Augmented Reality

Hello there!

I’m building an Augmented Reality Game with Unity MARS. My goal is to place a 3D labyrinth onto an image marker using PointGraphs. I’ve modified the example szene and it works fine. But when I try to project onto an image the grid doesn’t follow in world space. See image below:


I guess A* computes the grid upon start but then does not translate it in world space when the user places the game upon an image.

Is there a way to constantly recalculate the grid at runtime? Or another solution anybody might think of?

Much obliged


I would recommend that you keep the graph in a fixed location, and when you have calculated the path you transform the coordinates of the path so that it lines up with your image (applying the Transform’s coordinate system). You can also move the graph every frame (see PointGraph - A* Pathfinding Project) but if your graph is large this might be slow.

Hello @aron_granberg. Thanks for your answer. I’ve got feedback form the UNITY MARS people and they outlined this solution:

You could easily trigger the mesh recalculation after the image is matched just by adding a MatchAction to your proxy and then create an event that triggers a method that you write on your own that will get called when the condition on the proxy is met!

Actions reference guide | Unity MARS | 1.4.1 (

That might be a good solution, since then the graph would be automatically recalculated every time the user has successfully scanned the image.

I tested this approach manually inside UNITY MARS Simulation view and recalculated the graph (by hitting scan) once the image was placed on the wall. It worked well. (In Simulation)

I’m having trouble putting together the script the Unity Guy was talking about. I don’t know any C# :pensive: I found the documentation I was looking for, but obviously there is more to it, than just copy/paste it inside a C# script. Could you help me with that?

The Match Section looks like this. (see below)

Nice. That sounds like a good solution.

I can’t help you with the C# script I’m afraid. I haven’t used Unity MARS myself.
Btw, that’s some ancient documentation. The updated page is at Graph Updates during Runtime - A* Pathfinding Project

Ok, but as far as I understand the missing script would just have to call this A* function.

// Recalculate all graphs;

To close this topic the UNITY MARS Developers provided me this simple script:

using UnityEngine;
public class RecalculateGraph : MonoBehaviour {
    public void RecalculateThePathfindingGraph()  {
        Debug.Log("Graph is being recalculated!");
        // Recalculate all graphs;

I attached it to the MatchAction under my ImageMarker Proxy and set it to run on MatchAquire and on MatchUpdate and it works.

There are still some glitches, but hopefully those can be ironed out. AR is never a completely stable environment though.