ObjectPool and AI agents

nRedux

Member
I set up an AI agent and I use ObjectPool to create a pool for use in a scene. I have a spawner which gets the instances from the pool and places them in the world. The problem comes when an agent dies and is reused, the ragdoll is still active on them when they are spawned again.

I need to know the proper way to prepare a character for it to be spawned again. I looked into the CharacterRespawner and tried calling Respawn but this doesn't seem to work, the ragdoll is still active. Any ideas?
 

Justin

Administrator
Staff member
The character is respawned when the OnRespawn event is sent. You're looking in the correct location, except it's in the regular Respawner component instead of CharacterRespawner.
 

Justin

Administrator
Staff member
I would need to step through it in order to see exactly what is happening, but generally you don't need to do anything manually to respawn the character. The Respawner will correctly respawn the character if Schedule Respawn On Death is selected. You can see an example of this in the demo scene - it uses a ragdoll by default as well.

In this case it doesn't really matter that you spawned the agent using the object pool - with the ragdoll the agent is never being disabled.
 

Diggidy

Member
I am seeing this same issue. If an NPC is dead on the ground and ObjectPool.Instantiate is called it will instantiate an active dead NPC instead of an inactive NPC. This is what is causing the ragdoll to still be active. It would be ideal for the ObjectPool to instantiate an inactive NPC instead of an active NPC that is dead. A way around this is to deactivate the dead NPC right away but that takes a bit of the emersion away.
 
Top