- A* version: [5.4.6]
- Unity version: [6.3.16]
Hi, this is my first time using a forum, so please excuse me if I do this wrong.
I have a pretty serious bug: when my player passes through an area not scanned by the grid, the entire Astar Path thread dies, causing the Astar Path AI to stop working for the rest of the game.
These are the errors I get when this happens:
AssertionException: Assertion failure. Value was Null
Expected: Value was not Null
UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at :0)
UnityEngine.Assertions.Assert.IsNotNull[T] (T value, System.String message) (at :0)
UnityEngine.Assertions.Assert.IsNotNull[T] (T value) (at :0)
Pathfinding.ABPath.EndPointGridGraphSpecialCase (Pathfinding.Path+SearchContext& ctx, Pathfinding.NearestNodeConstraint nn, Pathfinding.NNInfo closestWalkableEndNode, UnityEngine.Vector3 originalEndPoint, System.Int32 targetIndex) (at ./Packages/com.arongranberg.astar/Pathfinders/ABPath.cs:274)
Pathfinding.ABPath.FindStartAndEndNodes (Pathfinding.Path+SearchContext& ctx, Pathfinding.NearestNodeConstraint& constraint) (at ./Packages/com.arongranberg.astar/Pathfinders/ABPath.cs:433)
Pathfinding.ABPath.Prepare (Pathfinding.Path+SearchContext& ctx) (at ./Packages/com.arongranberg.astar/Pathfinders/ABPath.cs:390)
Pathfinding.Path.Pathfinding.IPathInternals.Prepare (Pathfinding.Path+SearchContext& ctx) (at ./Packages/com.arongranberg.astar/Core/Pathfinding/Path.cs:1197)
Pathfinding.PathProcessor.CalculatePathsThreaded (Pathfinding.PathHandler pathHandler, Pathfinding.Sync.BlockableChannel`1+Receiver[T] receiver) (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:326)
UnityEngine.Debug:LogException(Exception)
Pathfinding.PathProcessor:CalculatePathsThreaded(PathHandler, Receiver) (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:395)
Pathfinding.<>c__DisplayClass27_0:b__0() (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:122)
System.Threading.ThreadHelper:ThreadStart()
And There :
Unhandled exception during pathfinding. Terminating.
UnityEngine.Debug:LogError (object)
Pathfinding.PathProcessor:CalculatePathsThreaded (Pathfinding.PathHandler,Pathfinding.Sync.BlockableChannel`1/Receiver<Pathfinding.Path>) (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:396)
Pathfinding.PathProcessor/<>c__DisplayClass27_0:b__0 () (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:122)
System.Threading.ThreadHelper:ThreadStart ()
And There :
Error : This part should never be reached.
UnityEngine.Debug:LogError (object)
Pathfinding.PathProcessor:CalculatePathsThreaded (Pathfinding.PathHandler,Pathfinding.Sync.BlockableChannel`1/Receiver<Pathfinding.Path>) (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:403)
Pathfinding.PathProcessor/<>c__DisplayClass27_0:b__0 () (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:122)
System.Threading.ThreadHelper:ThreadStart ()
My code is quite basic, it’s this one here:
using Mirror;
using Pathfinding;
using UnityEngine;
namespace VG.IA
{
public class MirrorIaPositionSync : NetworkBehaviour
{
private AIPath aiPath;
private AstarIA astarIA;
[SyncVar(hook = nameof(OnDestinationChanged))]
private Vector3 networkTargetDestination;
[SyncVar(hook = nameof(OnPositionTeleportCheck))]
private Vector3 serverTruePosition;
private float teleportCheckTimer;
void Awake()
{
aiPath = GetComponent<AIPath>();
astarIA = GetComponent<AstarIA>();
}
void Start()
{
if (isClientOnly && astarIA != null)
{
astarIA.enabled = false;
}
}
public void NetworkUpdateCustom(float dt)
{
if (!isServer) return;
if (aiPath != null && aiPath.destination != networkTargetDestination)
{
if (Vector3.SqrMagnitude(aiPath.destination - networkTargetDestination) > 0.5f)
{
networkTargetDestination = aiPath.destination;
}
}
teleportCheckTimer += dt;
if (teleportCheckTimer >= 1.5f)
{
teleportCheckTimer = 0f;
serverTruePosition = transform.position;
}
}
private void OnDestinationChanged(Vector3 oldDest, Vector3 newDest)
{
if (aiPath == null) return;
aiPath.destination = newDest;
if (!aiPath.pathPending)
aiPath.SearchPath();
}
private void OnPositionTeleportCheck(Vector3 oldPos, Vector3 newPos)
{
if (isServer) return;
if (Vector3.Distance(transform.position, newPos) > 2.5f)
{
transform.position = newPos;
}
}
}
}
I would greatly appreciate the help, thank you in advance.