Help With Dynamic Grid Penalty

Hello I based myself on DynamicGridObstacle to dynamically create penalties on my graphs, I will attach the code to this thread, it’s essentially pretty much the same code as DynamicGridObstacle only it adds penalty instead of making the node unwalkable.

Basically my agents would have a DynamicGridPenalty component on them, and the goal is to add a penalty to the node beneath them, so that other agents try and avoid that node for their path.

The problem is, the DynamicGridPenalty components of the agents interfere with each other when the agents are close, for example one would add a penalty, but the other would remove it.

DynamicGridPenalty.txt (11.5 KB)

Hi

This sounds like you want a custom ITraversalProvider instead. See Agent-Specific Pathfinding - A* Pathfinding Project

Okay I will take a look, my goal is to aide the RVOController to basically have my agents not get blocked by one another because I was having problems with it. I created a separate post about the problems I’ve encountered with RVOController.
So what I was trying to achieve here is, when my agents are calculating their path, I would like that path to avoid other agents when possible.

looking at the example from the docs of Agent-Specific Pathfinding - A* Pathfinding Project

public bool CanTraverse (Path path, GraphNode node) {
        // Make sure that the node is walkable and that the 'enabledTags' bitmask
        // includes the node's tag.
        return node.Walkable && (path.enabledTags >> (int)node.Tag & 0x1) != 0;
        // alternatively:
        // return DefaultITraversalProvider.CanTraverse(path, node);
    }

Does this mean, for every node on a given path, this method is called to figure out if we can path there or not? so my logic will go in this method where I would check that node to make sure no other agent is occupying it?

alright I tried it out, however it’s not ideal, there’s a significant performance hit, probably expected since now I’m doing a bunch more logic for every node.

I think for my purposes, if Scenario 3 of RVOController bugs when using Lock When Not Moving gets fixed, that pretty much would be great for my project, I wouldn’t need to try and do any other pathing work.

For TraversalProvider I needed to enable ‘calculatePartial’ (in case we don’t find a full path) as denoted by this warning:

Path Failed : Computation Time 3241.71 ms Searched Nodes 2171
Error: Searched all reachable nodes, but could not find target. This can happen if you have nodes with a different tag blocking the way to the goal. You can enable path.calculatePartial to handle that case as a workaround (though this comes with a performance cost).
Path Number 966 (unique id)
UnityEngine.Debug:LogWarning (object)
AstarPath:LogPathResults (Pathfinding.Path) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/AstarPath.cs:851)
AstarPath:<.ctor>b__81_3 (Pathfinding.Path) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/AstarPath.cs:653)
Pathfinding.PathProcessor:CalculatePathsThreaded (Pathfinding.PathHandler,Pathfinding.BlockableChannel`1/Receiver<Pathfinding.Path>) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/PathProcessor.cs:364)
Pathfinding.PathProcessor/<>c__DisplayClass27_0:<StartThreads>b__0 () (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/PathProcessor.cs:122)
System.Threading.ThreadHelper:ThreadStart ()

This is how I do, not sure where else I could do it if this is not the right way.

public bool CanTraverse(Path path, GraphNode node)
{
    if (path is ABPath abPath)
    {
        abPath.calculatePartial = true;
    }
    return DefaultITraversalProvider.CanTraverse(path, node) && ...
}

I then sometimes start seeing these exceptions:

NullReferenceException: Object reference not set to an instance of an object
Pathfinding.ABPath.CompletePartial () (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Pathfinders/ABPath.cs:444)
Pathfinding.ABPath.OnHeapExhausted () (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Pathfinders/ABPath.cs:451)
Pathfinding.Path.CalculateStep (System.Int64 targetTick) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/Path.cs:1007)
Pathfinding.Path.Pathfinding.IPathInternals.CalculateStep (System.Int64 targetTick) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/Path.cs:1074)
Pathfinding.PathProcessor.CalculatePathsThreaded (Pathfinding.PathHandler pathHandler, Pathfinding.BlockableChannel`1+Receiver[T] receiver) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/PathProcessor.cs:336)
UnityEngine.Debug:LogException(Exception)
Pathfinding.PathProcessor:CalculatePathsThreaded(PathHandler, Receiver) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/PathProcessor.cs:386)
Pathfinding.<>c__DisplayClass27_0:<StartThreads>b__0() (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/PathProcessor.cs:122)
System.Threading.ThreadHelper:ThreadStart()

And after that I get

Unhandled exception during pathfinding. Terminating.
0x00007ff62042a4bd (Unity) StackWalker::GetCurrentCallstack
0x00007ff62042f469 (Unity) StackWalker::ShowCallstack
0x00007ff621406da1 (Unity) GetStacktrace
0x00007ff621ac5782 (Unity) DebugStringToFile
0x00007ff61f379e76 (Unity) DebugLogHandler_CUSTOM_Internal_Log
0x00000248b94497ea (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
0x00000248b944965b (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
0x00000248b9448ade (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
0x00000248629a22ea (Mono JIT Code) UnityEngine.Debug:LogError (object)
0x000002481941bddb (Mono JIT Code) Pathfinding.PathProcessor:CalculatePathsThreaded (Pathfinding.PathHandler,Pathfinding.BlockableChannel`1/Receiver<Pathfinding.Path>) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/PathProcessor.cs:387)
0x000002481941a5eb (Mono JIT Code) Pathfinding.PathProcessor/<>c__DisplayClass27_0:<StartThreads>b__0 () (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/PathProcessor.cs:122)
0x00000247377081d2 (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart_Context (object)
0x00000247345c689e (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x00000247345c59eb (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x0000024737707363 (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object)
0x000002473770707b (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart ()
0x00000246eb250a68 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ffa143a4b6e (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
0x00007ffa142dd204 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
0x00007ffa142e0aed (mono-2.0-bdwgc) mono_runtime_delegate_try_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:4450)
0x00007ffa1430f9dd (mono-2.0-bdwgc) start_wrapper_internal (at C:/build/output/Unity-Technologies/mono/mono/metadata/threads.c:1296)
0x00007ffa1430fb9e (mono-2.0-bdwgc) start_wrapper (at C:/build/output/Unity-Technologies/mono/mono/metadata/threads.c:1348)
0x00007ffa65967344 (KERNEL32) BaseThreadInitThunk
0x00007ffa676626b1 (ntdll) RtlUserThreadStart

Followed by

Error : This part should never be reached.
0x00007ff62042a4bd (Unity) StackWalker::GetCurrentCallstack
0x00007ff62042f469 (Unity) StackWalker::ShowCallstack
0x00007ff621406da1 (Unity) GetStacktrace
0x00007ff621ac5782 (Unity) DebugStringToFile
0x00007ff61f379e76 (Unity) DebugLogHandler_CUSTOM_Internal_Log
0x00000248b94497ea (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
0x00000248b944965b (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
0x00000248b9448ade (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
0x00000248629a22ea (Mono JIT Code) UnityEngine.Debug:LogError (object)
0x000002481941bf93 (Mono JIT Code) Pathfinding.PathProcessor:CalculatePathsThreaded (Pathfinding.PathHandler,Pathfinding.BlockableChannel`1/Receiver<Pathfinding.Path>) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/PathProcessor.cs:394)
0x000002481941a5eb (Mono JIT Code) Pathfinding.PathProcessor/<>c__DisplayClass27_0:<StartThreads>b__0 () (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/PathProcessor.cs:122)
0x00000247377081d2 (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart_Context (object)
0x00000247345c689e (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x00000247345c59eb (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x0000024737707363 (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object)
0x000002473770707b (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart ()
0x00000246eb250a68 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ffa143a4b6e (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
0x00007ffa142dd204 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
0x00007ffa142e0aed (mono-2.0-bdwgc) mono_runtime_delegate_try_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:4450)
0x00007ffa1430f9dd (mono-2.0-bdwgc) start_wrapper_internal (at C:/build/output/Unity-Technologies/mono/mono/metadata/threads.c:1296)
0x00007ffa1430fb9e (mono-2.0-bdwgc) start_wrapper (at C:/build/output/Unity-Technologies/mono/mono/metadata/threads.c:1348)
0x00007ffa65967344 (KERNEL32) BaseThreadInitThunk
0x00007ffa676626b1 (ntdll) RtlUserThreadStart

After that whenever a path is trying to calculate i get

ArgumentException: The path is already pooled.
Pathfinding.PathPool.Pool (Pathfinding.Path path) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pooling/PathPool.cs:19)
Pathfinding.Path.Release (System.Object o, System.Boolean silent) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Pathfinding/Path.cs:712)
Pathfinding.Seeker.CancelCurrentPathRequest (System.Boolean pool) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/AI/Seeker.cs:226)
Pathfinding.AIBase.CancelCurrentPathRequest () (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/AI/AIBase.cs:549)
Pathfinding.AIPath.ClearPath () (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/AI/AIPath.cs:332)
Pathfinding.AIBase.SetPath (Pathfinding.Path path, System.Boolean updateDestinationFromPath) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/AI/AIBase.cs:629)
Assets.Scripts.TOW_Shared.Unit.UnitMovement.ResetPath () (at Assets/Scripts/TOW_Shared/Unit/UnitMovement.cs:62)
...