Skip to content
This repository was archived by the owner on Oct 20, 2021. It is now read-only.

Commit cb49e33

Browse files
Prevent multiple ragdolls being spawned on death (#29)
* Keep a local boolean flag to prevent multiple ragdolls being spawned between respawns
1 parent c1f8d72 commit cb49e33

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

workers/unity/Packages/com.improbable.gdk.ragdolls/Behaviours/RagdollSpawner.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,26 @@ public class RagdollSpawner : MonoBehaviour
1717
public RagdollSpawned OnRagdollSpawned;
1818

1919
private ObjectPool<PoolableRagdoll> pool;
20+
private bool hasRagdollSpawned;
2021

2122
private void OnEnable()
2223
{
2324
health.OnHealthModified += OnHealthModified;
25+
health.OnRespawn += (empty) => hasRagdollSpawned = false;
2426
pool = ObjectPooler.GetOrCreateObjectPool<PoolableRagdoll>(ragdollPrefab, 2);
2527
}
2628

2729
private void OnHealthModified(HealthModifiedInfo info)
2830
{
29-
if (info.Died)
31+
if (info.Died && !hasRagdollSpawned)
3032
{
3133
OnDeath(info.Modifier);
3234
}
3335
}
3436

3537
private void OnDeath(HealthModifier deathDetails)
3638
{
39+
hasRagdollSpawned = true;
3740
var ragdoll = pool.Get();
3841
if (transformToMatch != null)
3942
{

0 commit comments

Comments
 (0)