Adding Grid Grapg at runtime and use GraphUpdateScene

Hi,

I am adding grid graphs at runtime then scan using AstarPath.RegisterSafeUpdate. the problem is that it does not take in account the GraphUpdateScene. So any idea?

BTW; I also tested to make the GUS to update using a button and it works good and make part of the grid walkable.

So I think my question is does GUS works automatically when generating a new grid graph at runtime. or I have to call GUS.Apply() my self and if so is there a callback for the grid that I can register to, to apply the GUS.

Update 1:
Also note that ApplyOnScan = true;

Update 2:

zero reference so I think that’s why it does not update the graphs

Thanks in advance.

Hi

If you have created the GraphUpdateScene component before you created the graph and it has applyOnScan enabled, then it should trigger when the graph is scanned. It is triggered by the GraphUpdateScene.OnPostScan method.

Hi aron,

Thanks for the fast reply, I added a break point to the Apply method in the GraphUpdateScene and it does not get called.

could it be because I scan the grids not using AstarPath.active.Scan() instead I scan only one grid at a time:

AstarPath.RegisterSafeUpdate
(
delegate ()
{
AstarPath.active.graphs[index].ScanInternal();

                //Make sure the above graph update is done now
                AstarPath.active.FlushGraphUpdates();
            }
        );

Thanks again,

Hi

Ah.
Well, the ScanInternal method is – as the name implies and the documentation mentions – an internal method. You should not be calling it. In the currently released version there is unfortunately no way to scan a single graph at a time (this will be improved in a future version, in my local dev version you can scan graphs individually). You can work around this by in each loop in the ScanLoop (or ScanAsync depending on which version you are using) method in the AstarPath class do a check to see if that particular graph should be scanned (you can add some extra parameters to the method to get this information).

Though if you just want a really simple solution which will probably work in your case you can use

 AstarPath.active.graphs[index].ScanInternal();
 AstarPath.active.FloodFill();
 GraphModifier.TriggerEvent(GraphModifier.EventType.PostScan);
 GraphModifier.TriggerEvent(GraphModifier.EventType.LatePostScan);

Thanks. I think I will go with the simple solution.

Very helpful appreciating your help