> ## Documentation Index
> Fetch the complete documentation index at: https://xrlive.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Visual Lifecycle

> How the xRLive Launcher loads, runs, and unloads your visual

## Lifecycle overview

```
Mount .xrlive pak
       ↓
Load visual's Map
       ↓
Spawn UIpanelComponent (reads JSON config, creates operator UI)
       ↓
Create xRLive_Viewport widget (operator window preview)
       ↓
  [ Visual running ]
       ↓
Operator switches visual
       ↓
EndPlay → automatic cleanup
       ↓
Unmount pak
```

## What is cleaned up automatically

When a visual closes, the SDK cleans up everything registered during the visual's lifetime:

| Thing                                                   | Cleanup method                                    |
| ------------------------------------------------------- | ------------------------------------------------- |
| `xRLive_Viewport` widget and all its children           | `RemoveFromParent()` — automatic                  |
| Operator panel widget                                   | `RemoveFromParent()` — automatic                  |
| Actors placed in the visual's Map                       | Level unload — automatic                          |
| Actors spawned at runtime via `Spawn Visual Actor`      | `Destroy()` — automatic                           |
| Niagara effects registered via `Register Visual Effect` | `Deactivate()` + `DestroyComponent()` — automatic |
| MPC values registered via `Register MPC for Reset`      | Reset to asset defaults — automatic               |

## What you must manage yourself

<Warning>
  Anything spawned or modified at runtime that is **not registered** with the SDK will persist into the next visual.
</Warning>

If you use the standard **Spawn Actor from Class** node instead of `Spawn Visual Actor`, the spawned actor will **not** be cleaned up automatically. You have two options:

1. **Replace it** with `Spawn Visual Actor` — same inputs, auto-cleanup.
2. **Register it manually** by calling `Register Visual Actor` right after spawning.

The same applies to Niagara effects and MPC changes — always register them at the start of your visual's lifecycle (e.g., in `Event BeginPlay`).

## Best practices

* Use `Spawn Visual Actor` for any actor you create at runtime.
* Call `Register Visual Effect` on any looping Niagara system right after spawning it.
* Call `Register MPC for Reset` once on `Event BeginPlay` for every MPC your visual writes to.
* Do not use `Add to Viewport` for custom widgets — add them as children inside `xRLive_Viewport`'s named slots so they are removed automatically.
