Multiple UpdateGraph calls not working when back to back

Hello,

I noticed an issue that happens when I drag click to place multiple objects in a row, vs placing a single object at a time. When doing the former, Astar does not color code the pieces after they are placed, when looking at the Scene with Tag Graph Coloring turned on. The single piece placement method, however, does get a color coding applied.

This is causing my seekers to not be able to walk on the pieces that were placed in multiple numbers. For example, I could drag and place a series of sidewalk tiles, for human seekers to walk on, versus placing them one at a time.

I have also tried flushing graph immediately, but that didn’t help.

Could you post a screenshot /video of this. And possibly the code you use?

I will have to put an example together to demonstrate, but the code is the following for adding a piece:

private void UpdatePathfinderAddObject(GameObject newObj)
{
    Bounds bounds = newObj.GetComponent<Collider>().bounds;
    GraphUpdateObject guo = new GraphUpdateObject(bounds);
    guo.setTag = 1;
    guo.modifyTag = true;
    //guo.updatePhysics = false;
    AstarPath.active.UpdateGraphs(guo);
    if (_updateGraphImmediately) {
        AstarPath.active.FlushGraphUpdates();
    }
}

I know that on another thread, it was recommended that updatePhysics = false be added, but now it seems to make everything gray for me. I am also wondering if it would help if I push each graph update to its own frame, even though it might slow down the game a tiny bit.

My only other thought is that this is related to the piece only being .01 in height, and .01 off the floor, so as to not have rendering conflicts with the ground, although it does have a box collider. Still doesn’t explain why it would work for single placement and not multi placement.

Ok, so I have made some progress on this. It turns out that I was passing Vector3.zero as rotation to objects when multi placing them, versus single placement, which it didn’t like. Using the eulerAngles of the original prefab has solved the problem!

However, I am now still seeing an issue where deleting an object is not removing the tag’s color coding from that area.

Fixed the issue on deletion as well. Turns out I do need updatePhysics = false on deletion, but not on adding. Not sure why, but this seems to work at the moment.

Huh. Odd. Not sure why it would work exactly the same one by one and when adding multiple… Anyway, it seems to work now…

It was an error on my end in terms of the single item placement code, working slightly differently than the drag placing multiple items code. The latter was trying to reset all items being placed to a default rotation of 0 by using Vector3.zero, whereas the single place was using the prefab’s original eulerAngles from the start.

Apparently though, you can’t set rotation by using Vector3.zero, even though its supposed to represent a vector of (0,0,0). Passing transform.eulerAngles works though, and I’m still not 100% sure as to why.

I’m not quite sure what you mean. Setting transform.eulerAngles = Vector3.zero should reset the rotation to zero. Though slightly faster is to use transform.rotation = Quaternion.identity (they should be equivalent).

Thank you for the reply, and Happy Holidays!

One of the issues was indeed that I was setting rotation incorrectly. I am still, however, having an issue with UpdateGraphs where it seems to not register an item called during Start. The same item can then be placed later in game and is registered fine. This is an item .01 in size Y, which I suspect is part of the problem. Essentially, I am trying to place some objects for the user, right when the game starts, which they can place themselves later on as well.

Could you please recommend a debug location for trying to figure out why an item wasn’t accepted? Or perhaps an increased debugging level setting that would show this?

EDIT: One clue I just debugged was that It works fine when I instantiate the object by using the transform.eulerAngles of its prefab, but it doesn’t work if the gameObject is nested underneath another root prefab. I have a scenario where I have a blank root gameobject with nested objects that I need to instantiate during Start.

Do you think you could show me the code you use to create the objects? (both at start and later in the game).

Sorry for the late reply on this. I will have to spend time and duplicate a lot of the logic in a sample scene. Will eventually get to it when I get back to working on some pathfinding tasks. Thanks!

1 Like