> For the complete documentation index, see [llms.txt](https://plugn-play.gitbook.io/ultimate-dice-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://plugn-play.gitbook.io/ultimate-dice-system/initialization.md).

# Initialization and Lifecycle

Control when the manager starts and which PlayerControllers receive a thrower.

## Explicit initialization

Call **InitializeDiceManager** on your placed `BP_DiceManager` from an authority/server execution path. This event:

1. Uses its assigned Dice Configuration, falling back to `DA_DiceConfig_Default` if the reference is invalid.
2. Finds eligible player controllers and ensures each has a thrower owned by that controller.
3. Starts a repeating player synchronization timer at **0.5-second** intervals.

The continuing synchronization allows eligible players discovered later to receive a thrower. Existing throwers are identified by their owner so the manager does not create another for the same controller.

Use **one manager per world**. Some result and history paths resolve the manager with `Get Actor Of Class`, so multiple managers do not form independent dice systems automatically.

## Tag filtering

These settings are grouped under **Advanced → Initialization** in the Data Asset.

| Setting                            | Purpose                                                                          |
| ---------------------------------- | -------------------------------------------------------------------------------- |
| Initialize Only Tagged Controllers | Restricts creation of new throwers to controllers with the configured Actor Tag. |
| Controller Tag                     | The Actor Tag to check; currently `DiceThrower`.                                 |

This uses **Actor Tags**, not the Gameplay Tags system. Apply the tag to the **PlayerController**, not just its pawn.

The filter controls creation. Removing a tag after a thrower has already been created does not automatically revoke or destroy that thrower.

## The included demo

`BP_DiceDemoGameMode` calls `InitializeDiceManager` after a one-second BeginPlay delay. It is a demo integration convenience; reusable Dice logic does not require that custom GameMode.

`BP_DiceDemoCharacter` supplies a simple controllable pawn with a visible cylinder. It is optional when integrating with your own pawn.

## Configuration delivery to clients

The manager keeps the selected Data Asset as its server-side configuration reference. Each thrower and spawned die replicates a **DiceConfigurationPath** instead of replicating the Data Asset object itself.

On a client, `OnRep_DiceConfigurationPath` loads the asset from that path, casts it to `BP_DiceConfig`, stores the local Dice Configuration reference and applies its settings. The owning thrower can then initialize its input and HUD. Its existing initialization timer also handles the controller ownership becoming available later.

Keep the selected preset and its dependencies included in the client build. This sends the identity of a preset; it does not transmit arbitrary edits to the Data Asset's contents during play.

## Configuration timing

Select the Data Asset before initialization. Its values are applied to the thrower during configuration, and to individual dice when they are spawned.

Changing the manager's Data Asset reference does not provide a general live-reload mechanism for all existing throwers and dice. Use the supplied runtime controls for current-player changes; for a new baseline preset, stop play, assign the preset and initialize again.

## Lifecycle

```mermaid
flowchart TD
    A[Server calls InitializeDiceManager] --> B[Find eligible PlayerControllers]
    B --> C[Create owned thrower if missing]
    C --> D[Owner installs input and HUD]
    D --> E[Player requests a throw]
    E --> F[Server spawns and configures dice]
    F --> G[Dice resolve their results]
    G --> H[Roll record completes the batch]
    H --> I[Update history and best scores]
    H --> J[Broadcast RollResults on server]
```

Manager EndPlay clears its synchronization timer. Thrower EndPlay removes its input context and HUD, clears its update timer and restores its camera state.
