When an NPC using my custom npc_behaviour, which spawns a coroutine during OnBegin(), is eliminated, the spawned coroutine is cancelled.

Please select what you are reporting on:


What Type of Bug are you experiencing?



I have a Player Manager and a Custom NPC Behaviour file. I have a function in my Player Manager called Stun(), which I call using spawn{player_manager.Stun(PlayerCharacter)} from my Custom NPC Behaviour when the enemy damages the player. The Stun() puts the player into stasis and starts a countdown to release the player. If Stun() is called again while already active, the time remaining will be increased. If the NPC is eliminated after enough stun time has been accumulated for it to last beyond the time it takes the game to clean up the eliminated NPC, the spawned Stun() is cancelled alongside the eliminated NPC being removed from the game.

Steps to Reproduce

Create a custom npc_behavior class, assign it to a custom character and spawn it using an NPC spawner device. Have the NPC spawn a public function from the player-manager that contains a long loop with some output. Eliminate the NPC.

Greatly simplified, my code structure is like this:


player_manager<public>:= module: 


            Print("loop running")


custom_npc_behavior := class(npc_behavior):

    OnBegin<override>()<suspends>:void =


Expected Result

The spawned coroutine would continue forever or until complete.

Observed Result

The spawned coroutine is cancelled alongside the eliminated NPC being cleaned up.



Could anyone share a way for me to call this function by some action of my custom NPC while being fully disconnected so that the function doesn’t die along with the NPC?