# BP_CoreGameState — Asset Implementation

> **UE5 Asset:** `/Game/Framework/Core/BP_CoreGameState`
> **Parent Class:** `GS_CoreGameState` (C++) or `GameStateBase`
> **Asset Type:** Blueprint Class (GameState)

---

## Create This Asset

### Step 1: Create Blueprint
1. Content Browser → `Content/Framework/Core/`
2. Right-click → **Blueprint Class**
3. Parent: `GS_CoreGameState` (C++) OR `GameStateBase`
4. Name: `BP_CoreGameState`

### Step 2: Assign in GameMode
Open `BP_CoreGameMode` → Class Defaults → `GameState Class` → `BP_CoreGameState`

---

## What to Wire

### Variables (if BP-only GameStateBase)

| Variable | Type | Replication | Default |
|----------|------|-------------|---------|
| `ElapsedPlayTime` | `Float` | Replicated | `0.0` |
| `ActiveChapterTag` | `GameplayTag` | Replicated | Empty |
| `ActiveNarrativePhase` | `GameplayTag` | Replicated | Empty |
| `bEncounterActive` | `Boolean` | Replicated | `false` |
| `ActiveObjectiveTags` | `Array<GameplayTag>` | Replicated | Empty |

### Override: BeginPlay
```
[Event BeginPlay]
  ├─ Parent: BeginPlay
  ├─ Get GameInstance → Cast to GI_GameFramework → Store as CachedFramework
  └─ Enable Tick
```

### Override: Tick
```
[Event Tick]
  ├─ IsValid(CachedFramework)? AND CurrentGamePhase == InGame?
  │   True → ElapsedPlayTime += DeltaSeconds
  │   ├─ TimeUpdateAccumulator += DeltaSeconds
  │   └─ Accumulator >= 1.0?
  │       ├─ Reset accumulator
  │       └─ Call OnElapsedPlayTimeUpdated(ElapsedPlayTime)
```

### Function: SetChapter
```
Input: ChapterTag (GameplayTag)
[Server-only]
  ├─ If ChapterTag == ActiveChapterTag → Return
  ├─ Set ActiveChapterTag = ChapterTag
  └─ Call OnChapterChanged(ChapterTag)
```

### Function: AddObjective / RemoveObjective
```
AddObjective(ObjectiveTag):
  ├─ If already in array → Return
  ├─ Add to ActiveObjectiveTags
  └─ Call OnObjectiveTagsChanged

RemoveObjective(ObjectiveTag):
  ├─ Remove from array
  └─ Call OnObjectiveTagsChanged
```

### Event Dispatchers to Create
| Dispatcher | Parameters |
|------------|-----------|
| `OnElapsedPlayTimeUpdated` | `ElapsedSeconds` (Float) |
| `OnChapterChanged` | `NewChapter` (GameplayTag) |
| `OnNarrativePhaseChanged` | `NewPhase` (GameplayTag) |
| `OnEncounterActiveStateChanged` | `bActive` (Boolean) |
| `OnObjectiveTagsChanged` | (none) |

---

## Test It
- [ ] PIE: check that GS_CoreGameState spawns
- [ ] Call SetChapter → OnChapterChanged fires → HUD updates
- [ ] Call AddObjective → OnObjectiveTagsChanged fires → objective list refreshes
