# BPC_PersistentCorpseSystem — Actor Component (Persistent Corpse)

**File:** [`Content/Framework/Save/BPC_PersistentCorpseSystem`](Content/Framework/Save/BPC_PersistentCorpseSystem.uasset)

**Purpose:** Spawns a persistent corpse actor at the death location. The corpse remains in the world and can be interacted with (looted, examined) after respawn.

**Depends On:** [`BPC_DeathHandlingSystem`](BPC_DeathHandlingSystem.md), [`SS_SaveManager`](35_SS_SaveManager.md), [`I_Persistable`](36_I_Persistable.md)
**Used By:** [`BPC_DeathHandlingSystem`](BPC_DeathHandlingSystem.md) (orchestrator)

---

## Variables

| Name | Type | Description |
|------|------|-------------|
| `CorpseActorClass` | Actor Class Reference | Blueprint class for the corpse actor (e.g., BP_PlayerCorpse) |
| `ActiveCorpse` | Actor Reference | The spawned corpse in the world |
| `bSpawnCorpseOnDeath` | Bool | Toggle: should a corpse be spawned? |
| `CorpseLifetime` | Float | Seconds before corpse auto-destroys (default 300.0) |
| `bPersistCorpseAcrossSaves` | Bool | If true, corpse is saved via I_Persistable |

---

## Functions

| Name | Inputs | Outputs | Description |
|------|--------|---------|-------------|
| `SpawnCorpse` | Context: S_DeathContext | Actor Reference | Spawns the corpse BP at DeathLocation |
| `DestroyCorpse` | — | — | Removes the corpse from the world |
| `GetCorpseLocation` | — | Vector | Returns the active corpse's world location |
| `HasActiveCorpse` | — | Bool | Is there a corpse in the world? |

---

## Event Dispatchers

| Name | Parameters | Fired When |
|------|-----------|------------|
| `OnCorpseSpawned` | CorpseActor: Actor Reference | Corpse appears in the world |
| `OnCorpseDestroyed` | — | Corpse is cleaned up |
| `OnCorpseLooted` | CorpseActor: Actor Reference | Player loots the corpse |

---

## Blueprint Flow

```
[SpawnCorpse: Context]
  └─► If !bSpawnCorpseOnDeath → return null
  └─► Spawn Actor of CorpseActorClass at Context.DeathLocation
  └─► Set corpse appearance based on DeathContext (pose, damage visuals)
  └─► Set ActiveCorpse = spawned actor
  └─► If bPersistCorpseAcrossSaves:
         Register corpse with SS_SaveManager via I_Persistable
  └─► Start CorpseLifetime auto-destroy timer
  └─► Broadcast OnCorpseSpawned

[DestroyCorpse]
  └─► If ActiveCorpse is valid:
         If bPersistCorpseAcrossSaves: Unregister from SS_SaveManager
         Destroy ActiveCorpse actor
         Set ActiveCorpse = null
         Broadcast OnCorpseDestroyed

[CorpseLifetime Timer]
  └─► When timer expires:
         DestroyCorpse()
```

---

## Communications With

| Target System | Method | Why |
|---------------|--------|-----|
| [`BPC_DeathHandlingSystem`](BPC_DeathHandlingSystem.md) | Direct call | Orchestrator triggers spawn/destroy |
| [`SS_SaveManager`](35_SS_SaveManager.md) | Direct call | Persist corpse across save/load |
| [`I_Persistable`](36_I_Persistable.md) | Interface | Corpse actor implements for serialization |
| [`BPC_InteractionDetector`](../03-interaction/16_BPC_InteractionDetector.md) | Dispatcher | Player can interact with corpse (loot) |
| [`BPC_InventorySystem`](../04-inventory/BPC_InventorySystem.md) | Direct call | Transfer loot items to player |

---

## Reuse Notes
- Corpse persistence across saves requires the corpse actor to implement `I_Persistable`
- CorpseLifetime default of 300 seconds can be configured per level
- Loot interaction routes through InteractionDetector and InventorySystem
- Split from original bundled `31_BPC_DeathHandlingSystem.md` per Clean Slate refactoring plan