NullReferenceException: Object reference not set to an instance of an object
Pathfinding.AIPath.ClampToNavmesh (UnityEngine.Vector3 position, System.Boolean& positionChanged) (at ./Library/PackageCache/com.arongranberg.astar@4.3.77/Core/AI/AIPath.cs:478)
Pathfinding.AIBase.FinalizePosition (UnityEngine.Vector3 nextPosition) (at ./Library/PackageCache/com.arongranberg.astar@4.3.77/Core/AI/AIBase.cs:801)
Pathfinding.AIBase.FinalizeMovement (UnityEngine.Vector3 nextPosition, UnityEngine.Quaternion nextRotation) (at ./Library/PackageCache/com.arongranberg.astar@4.3.77/Core/AI/AIBase.cs:762)
Pathfinding.AIBase.OnUpdate (System.Single dt) (at ./Library/PackageCache/com.arongranberg.astar@4.3.77/Core/AI/AIBase.cs:506)
Pathfinding.AIBase.OnUpdate (Pathfinding.AIBase[] components, System.Int32 count, UnityEngine.Jobs.TransformAccessArray transforms, Pathfinding.Util.BatchedEvents+Event ev) (at ./Library/PackageCache/com.arongranberg.astar@4.3.77/Core/AI/AIBase.cs:480)
Pathfinding.Util.BatchedEvents+<>c__DisplayClass15_0`1[T].b__0 (System.Object[] objs, System.Int32 count, UnityEngine.Jobs.TransformAccessArray tr, Pathfinding.Util.BatchedEvents+Event ev) (at ./Library/PackageCache/com.arongranberg.astar@4.3.77/Utilities/BatchedEvents.cs:177)
Pathfinding.Util.BatchedEvents.DoEvent (Pathfinding.Util.BatchedEvents+Event eventType) (at ./Library/PackageCache/com.arongranberg.astar@4.3.77/Utilities/BatchedEvents.cs:200)
Pathfinding.Util.BatchedEvents.Update () (at ./Library/PackageCache/com.arongranberg.astar@4.3.77/Utilities/BatchedEvents.cs:212)
I debugged it and found the rvoController.rvoAgent == null after I disable the GameObject which has the component of RVOCOntroller by pool manager
it occurs very frequently, it will show every time I recycle the GameObject by pool manager
Hi
When are you disabling the agent?
The RVOController should always have an rvoAgent set when it is enabled. It is literally set in the OnEnable function.
Does the error happen as you disable the agent, or once you enable it again?
hello, I’m using LeanPool for pool manager
The agent is created by LeanPool.Spawn(agentPrefab) and recycled by LeanPool.Despawn(agentInstance)
the error will occur every time after I called the Despawn.
here is the lean pool and it is a free asset
Hi
I mean, when are you doing this in Unity’s update cycle? Is it when a particular event happens?
hello, just make a small example for you to reproduce this problem using the example16_RVO 2D
put the Starter component at Test(1)
then replace the component of AIPath in AI(28) with MyAIPath and make a prefab by Ai(28), delete AI(28) from scene
link the prefab of AI(28) to AI in Starter and Target 1 to D
then run it, when the agent arrive the destination, the error occur
using System;
using Lean.Pool;
using Pathfinding;
using UnityEngine;
namespace DefaultNamespace
{
public class MyAIPath : AIPath
{
private void Update()
{
}
public override void OnTargetReached () {
canMove = false;
LeanPool.Despawn(this);
}
void OnDisable()
{
base.OnDisable();
destination = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
}
}
}
using System;
using Lean.Pool;
using Pathfinding;
using UnityEngine;
namespace DefaultNamespace
{
public class Starter : MonoBehaviour
{
public GameObject ai;
public Transform d;
private void Awake()
{
var a = LeanPool.Spawn(ai);
a.transform.parent = transform;
a.transform.localPosition = new Vector3(3, 2, 0);
a.GetComponent<AIDestinationSetter>().target = d;
}
}
}
Ah, you are disabling it during OnTargetReached. That’s in the middle of the movement calculations, which is probably what’s causing the issues.
As a workaround, I would recommend that you poll ai.reachedDestination
during Update instead. Generally, ai.reachedDestination is more robust anyway, and is the recommended way to do this.