I have an object pooler that is (mostly) working with the A* stuff. If i set the pool to something really high (more than i would ever spawn), like say 20 units. as long as there aren’t 21 units on the screen, everthing works… the second you need a 21st unit my pooler tries to instantiate a new unit in the pooler. When this happens it first checks the status of the gameobject to pool (if its visible or not). and if its visible, it stores that value (true). Disables the game object… instantiates it… then enables it… (false to true). When I do this… BOOM I get this error below…
MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Transform.get_localScale () (at <4746c126b0b54f3b834845974d1a9190>:0)
Pathfinding.RVO.RVOController.UpdateAgentProperties () (at Library/PackageCache/com.arongranberg.astar@4.3.61/RVO/RVOController.cs:417)
Pathfinding.RVO.SimulatorBurst.PreCalculation () (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/RVO/RVOCoreSimulatorBurst.cs:1064)
Pathfinding.RVO.SimulatorBurst.UpdateInternal[T] () (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/RVO/RVOCoreSimulatorBurst.cs:1115)
Pathfinding.RVO.SimulatorBurst.Update () (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/RVO/RVOCoreSimulatorBurst.cs:1074)
Pathfinding.RVO.RVOSimulator.Update () (at Library/PackageCache/com.arongranberg.astar@4.3.61/RVO/RVOSimulator.cs:135)
If I instantiate a new object visible and I don’t go from false to true it works fine… but the problem with this is that when the pooler first sets up its pool they all need to instantiate false into the pool so they aren’t visible… since you haven’t spawned anything from the pooler…
This is the code to “add one new game object to the pool” if I need 1 extra that hasn’t been in the pool (21 vs 20)
protected override GameObject AddOneObjectToThePool()
{
if (GameObjectToPool == null)
{
Debug.LogWarning("The "+gameObject.name+" ObjectPooler doesn't have any GameObjectToPool defined.", gameObject);
return null;
}
bool initialStatus = GameObjectToPool.activeSelf;
GameObjectToPool.SetActive(false);
GameObject newGameObject = (GameObject)Instantiate(GameObjectToPool);
GameObjectToPool.SetActive(initialStatus);
SceneManager.MoveGameObjectToScene(newGameObject, this.gameObject.scene);
if (NestWaitingPool)
{
newGameObject.transform.SetParent(_waitingPool.transform);
}
newGameObject.name = GameObjectToPool.name + "-" + _pooledGameObjects.Count;
_pooledGameObjects.Add(newGameObject);
_objectPool.PooledGameObjects.Add(newGameObject);
return newGameObject;
}
the line
GameObjectToPool.SetActive(false);
and
GameObjectToPool.SetActive(initialStatus);
cause the transport error to blow. if i comment those 2 lines it doesn’t throw the transport error but I would rather keep those lines in if possible and possibly fix the RVO Controllers some other way on each enemy?
I am using RVO Controller / Seeker / Funnel on a Recast Graph.
any suggestions or thoughts?