Inconsistent updating of grid graph

I’m trying to update my graph using the following

    GraphUpdateObject GUO = new GraphUpdateObject();

    GUO.modifyTag = true;

    var pos = World.ConvertTileToWorldCordsNoOffset(x, y);

    Bounds b = new Bounds(pos, new Vector3(2.5f, 2.5f, 2.5f));

    GUO.bounds = b;

    AstarPath.active.UpdateGraphs(GUO);

this seems only work randomly and i have no idea on how to fix it

Hi

Could you give some more details?
What are you trying to achieve, and what do you mean by randomly? Only on certain positions? Only at certain times (even at the same spot)? Or something else?
Also, which version are you using?

Note that if you just want to change one tile in the graph, it might be easier to do something like this:

// Create a work item, this will run the delegate once the pathfinding threads have paused (it's not a good idea to modify the graph at the same time as pathfinding is running in separate threads)
AstarPath.active.AddWorkItem(() => {
    var grid = AstarPath.active.data.gridGraph;
    grid.GetNode(x,y).Tag = someValueHere;
});

Off the top of my head, it looks like you’re trying to set a tag over a certain area… but which tag are you setting? My game does something similar, so using your names/functions:

// Change this to whatever tag number you want to set
int tagToSet = 4;

// Did you mean "Coords" here for "Coordinates"?
Vector3 pos = World.ConvertTileToWorldCordsNoOffset(x, y);
Bounds b = new Bounds(pos, new Vector3(2.5f, 2.5f, 2.5f));

// This is a shortcut for creating/setting things on an object all at once
GraphUpdateObject GUO = new GraphUpdateObject() {
    modifyTag = true,
    setTag = tagToSet,
    bounds = b,
};

AstarPath.active.UpdateGraphs(GUO);

The documentation for modifyTag mentions needing setTag to be provided as well, here: https://arongranberg.com/astar/docs/graphupdateobject.html

It’s also possible that the Vector3 position coming from your ConvertTileToWorldCordsNoOffset function is too far away in world space to intersect the graph, even with a 2.5f cube being used as the bounds.

Hope this helps! Aron will of course know better, but maybe this can get you thinking about troubleshooting :slight_smile:

1 Like

sorry for the lack of info
im just using the change tag to see if it updates
by randomly i ment that when call on the same area it somtimes update and somtimes dont

i’ll try to upload som images of the problem as soon as i have time

edit: it seems that DynamicGridObstacle works
i’'m also using 4.2.3 if that helps

1 Like