Unable to pool

I get the following error (and therefore not instancing the game object) when I try to spawn the explosion on the Health script (spawned objects on death)


Unable to pool Flack Aerial Random(Clone) (instance -144360): the GameObject was not instantiated with ObjectPool.Instantiate 86,92375
UnityEngine.Debug:LogError(Object)
Opsive.UltimateCharacterController.Game.ObjectPool:DestroyInternal(GameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/ObjectPool.cs:254)
Opsive.UltimateCharacterController.Game.ObjectPool:Destroy(GameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/ObjectPool.cs:242)
Opsive.UltimateCharacterController.Objects.Explosion:Destroy() (at Assets/Opsive/UltimateCharacterController/Scripts/Objects/Explosion.cs:220)
Opsive.UltimateCharacterController.Game.ScheduledEvent:Invoke() (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:80)
Opsive.UltimateCharacterController.Game.Scheduler:Invoke(ScheduledEventBase, Int32) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:657)
Opsive.UltimateCharacterController.Game.Scheduler:Update() (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:308)

Any idea? I don't see the gameobject being pooled o the Game Controller. Thanks.
 
Can you list the steps to reproduce? As a test I added the CrateExplosion to the Spawned Objects On Death array in the demo scene and didn't receive the warning.
 
Maybe because you added ParticlePooler to a prefab which does not have a Particle System? In my case, that's the cause.
 
Last edited:
Also, he suggests simplifying the code and removing ObjectPool. Maybe that's why he does not create it correctly?

SpawnExplosion2.png
 
That error indicates that the object either wasn't spawned with ObjectPool.Instantiate but was destroyed with ObjectPool.Destory, or you are calling ObjectPool.Destroy multiple times on the same object.

Also, the Object Pool component doesn't have an overload which takes a transform so it is going back to Unity's instantiate method.
 
Last edited:
Also, the Object Pool component doesn't have an overload which takes a transform so it is going back to Unity's instantiate method.
@Justin maybe you could add this to the official documentation?

When refactoring code to use your pooling, I was running into the same problem, because my old code used the "wrong" overload of Instantiate. After loosing some hair, I finally found your post ;)

Pooling works great now, but a little bit more detail Information about ideal setup and what is going on under the hood would be appreciated!
 
Last edited:
Top