A* Pathfinding Project

GraphUpdateScene not updating Tag and Tag display problem


#1

I cannot seem to make GraphUpdateScene to work on my graph.

I have navmesh cuts using IsDual on my objects and I want to mark the cuts with specific tag. The debug tag display is totally blank:

With solid color display I can see the cuts correctly:

PS. Its on Unity 2018.3.1f


#2

Hi

That’s odd… I’m not sure what could be happening. Does nothing show even if you enable the ‘Show Surface’ toggle in the graph settings?

Tags and navmesh cuts do however not really work well together. The reason is that as a navmesh cut moves around, it’s pretty much impossible to determine how the tags of the nodes should change as the new node boundaries do not line up with the old ones. If the node stays exactly the same after a navmesh cut update was made then the tag will be kept, but otherwise it will be reset to zero.


#3

Yes, it does not shows even with show surface.

My cuts would be static once it has been made. It would actually be nice if the dual cut could tag the new nodes immediately.

How to control the order when the cut is made and the tag is applied with GraphSceneUpdate?


#4

If you really want to be sure that you force it you could do something like this:

AstarPath.active.navmeshUpdates.ForceUpdate();
AstarPath.active.FlushWorkItems();
graphUpdateScene.Apply();

Which version of the package are you using?


#5

I’m using newest version 4.2.4.


#6

Strange. I will have to look into why that might not be working. Is it only the tag mode or is any other display mode not working?


#7

Hi Aron,

It’s just the tag mode, regardless of the surface setting.

I will test now to see if the tags are actually set.

One more question, I noticed the TAG is uint. Does it mean I can assign arbitrary int from entire range? This would be very beneficial for me because I could tag the cuts underneath my buildings with unique int, it will help me with finding the building outline area.

Thanks for help and get well!


#8

Hi

No, tags must be in the range 0…31. It is possible to modify the code to allow arbitrary integers though. Essentially you just have to change the property implementation to use a separate field for the tag instead of using bit-packing. By default it does not do this due to the increased memory usage.


#9

I found the code for the mask:

		/// <summary>Start of tag bits. See: <see cref="Tag"/></summary>
		const int FlagsTagOffset = 19;
		/// <summary>Mask of tag bits. See: <see cref="Tag"/></summary>
		const uint FlagsTagMask = (32-1) << FlagsTagOffset;

It seems there is 12 bits for tag, so in practice I could store up to 2048 in the tag?

EDIT:

NVM I read the mask wrong.


#10

Hi Aron,

The Tag display is working:

However, I had to delay the GraphupdateScene application by 20s since game startup, I guess it’s due to all the graphs scanning and recalculation. My current code which works is the following:

            if ((AstarPath.active.isScanning
                 || AstarPath.active.IsAnyGraphUpdateInProgress
                 || AstarPath.active.IsAnyGraphUpdateQueued
                 || AstarPath.active.IsAnyWorkItemInProgress
                ) == false
                && Time.realtimeSinceStartup > 20)
            {
                var graphUpdate = GetComponent<GraphUpdateScene>();
                if (graphUpdate.enabled == false)
                {
                    graphUpdate.enabled = true;

                    AstarPath.active.navmeshUpdates.ForceUpdate();
                    AstarPath.active.FlushWorkItems();

                    graphUpdate.Apply();
                }
            }

Can you suggest how can I determine the cut has been applied to the graph and everything processed, so I can apply the graph update?


#11

That’s odd. Once the graph is scanned you really shouldn’t have to wait at all. What happens if you remove the 20 seconds check?

The ForceUpdate + FlushWorkItems call will ensure that the cuts are done immediately, so when FlushWorkItems has run it is guaranteed that all navmesh cuts have been applied.


#12

I went ahead and derived from NavmeshCut and introduced IsApplied field, so in the GraphUpdateScene I wait untill the corresponding cut is applied:

public class AdvancedNavmeshCut : NavmeshCut
{
	public bool IsApplied { get; set; }

	public override void NotifyUpdated()
	{
		IsApplied = true;

		base.NotifyUpdated();
	}
}
public class DelayedGraphUpdateScene : GraphUpdateScene
{
        public bool IsApplied;
        private bool workItemsFlushed = false;

        private AdvancedNavmeshCut[] _meshCuts;

        public void Update()
        {
            if (Application.isPlaying == false)
            {
                return;
            }

            if (_meshCuts == null)
            {
                _meshCuts = GetComponents<AdvancedNavmeshCut>();
            }

            if (IsApplied == false
                && workItemsFlushed)
            {

                Apply();

                AstarPath.active.FlushWorkItems();

                IsApplied = true;
            }

            if (IsApplied == false
                && workItemsFlushed == false
                && _meshCuts != null
                && _meshCuts.Length > 0
                && _meshCuts.All(m => m.IsApplied))
            {
                AstarPath.active.navmeshUpdates.ForceUpdate();
                AstarPath.active.FlushWorkItems();

                workItemsFlushed = true;
            }
        }
}

Everything is working fine for me with those classes, thanks for all the help.


#13

Cool but NotifyUpdated is an internal method. Were you modifying source of NavmeshCut.

Is it possible to achieve similar functionality without modification.


#14

Yes, you need to modify the source code for AStar to achieve this. The modification is minimal so I don’t see this as a problem, all you need to do is change the access modifier to public for the method in following classes:

  • NavmeshClipper
  • NavmeshAdd
  • NavmeshCut

Also since my original post I noticed I need to delay the Tag update by 1 frame to resolve some strange problems (I modified my original post). Since then, I had no issues with this approach.


#15

Ok thx. Anyway I’m baffled why we have to do all this to just cut a piece of geometry and change it’s tag. It sounds like such an obvious functionality that just adding NavmeshCut with GraphUpdateScene (without any region specified) should automagically do it’s work.


#16

@koirat

Yeah. When the NavmeshCut class was written, I did not think anticipate that people would want to set weights and tags like that, even though in hindsight I should have thought about it. To do it properly I really should make tag adjustment built in to the NavmeshCut component as that would make the modification much cleaner and faster and more reliable. But as it is right now, this is unfortunately the workaround that has to be done.