> ## Documentation Index
> Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt
> Use this file to discover all available pages before exploring further.

# ModalManager

> Message, confirmation, loading, and typed modal hosting.

**File:** `Packages/com.molca.core/Runtime/Modals/ModalManager.cs`\
**Type:** `RuntimeSubsystem` (child of [RuntimeManager](/core/runtime-manager) prefab)

## When to use

Use `ModalManager` for built-in modal types (message toasts, confirmation dialogs, loading overlays). For product-specific or complex modals (text input, selection, progress with custom UI), see [Shared modals](/shared/modals).

## Role

Shows informational messages, confirmations, loading overlays, and typed modals by key. Prefabs and canvas wiring are assigned on the subsystem component in the Inspector via `ModalEntry[]` keyed entries.

## Code

```csharp theme={null}
using Molca.Modals;
using UnityEngine;

public class ScoreReporter : MonoBehaviour
{
    public void ShowResult(string text)
    {
        ModalManager.Instance.AddMessage(text, ModalManager.MessageType.Default, 5f);
    }
}
```

Use **`ModalManager.Instance`** only after **`RuntimeManager`** has created the subsystem (e.g. after **`await RuntimeManager.WaitForInitialization()`**).

## API Reference

### Messages

| Method       | Signature                                                                              | Description                                                                                                |
| ------------ | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `AddMessage` | `void AddMessage(string message, MessageType msgType = Default, float duration = 10f)` | Queue a toast message with type and auto-close duration. Deferred one frame to avoid UI rebuild conflicts. |

### Loading overlays

| Method                  | Signature                                    | Description                                                                                                               |
| ----------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `AddLoading`            | `ModalLoading AddLoading(string title)`      | Add a titled loading indicator to the loading root. Returns the `ModalLoading` instance, or null if title already exists. |
| `RemoveLoading`         | `void RemoveLoading(string title)`           | Remove a loading indicator by title.                                                                                      |
| `ShowFullScreenLoading` | `void ShowFullScreenLoading(string message)` | Show the full-screen loading overlay with the given message.                                                              |
| `HideFullScreenLoading` | `void HideFullScreenLoading()`               | Hide the full-screen loading overlay.                                                                                     |

### Modals

| Method           | Signature                                                               | Description                                                                                        |
| ---------------- | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `ShowModal`      | `BaseModal ShowModal(BaseModal modalPrefab, bool defaultParent = true)` | Instantiate and show a modal from its prefab. Defaults to parenting under the modal panel content. |
| `ShowModal`      | `BaseModal ShowModal(string modalKey)`                                  | Show a modal registered under a key in the Inspector's `ModalEntry[]` list.                        |
| `ShowModal<T>`   | `T ShowModal<T>(string modalKey) where T : BaseModal`                   | Show and return a typed modal by key (e.g. `ShowModal<ModalConfirmation>("confirm")`).             |
| `CloseModal`     | `void CloseModal(BaseModal modal)`                                      | Untrack and close a specific modal. The caller owns calling `modal.Close()` first.                 |
| `CloseAllModals` | `void CloseAllModals()`                                                 | Close and destroy all currently active modals.                                                     |

### Confirmations

| Method                     | Signature                                                                                                                                                                                           | Description                                                                                      |
| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| `ShowRegularConfirmation`  | `ModalConfirmation ShowRegularConfirmation(string title, string message, string yesText, string noText, Action onYes, Action onNo, bool showNoButton = true)`                                       | Show the standard title + message confirmation dialog. Returns the `ModalConfirmation` instance. |
| `ShowAdvancedConfirmation` | `ModalConfirmation ShowAdvancedConfirmation(string title, string subtitle, string mainMessage, string details, string yesText, string noText, Action onYes, Action onNo, bool showNoButton = true)` | Show the advanced confirmation with title, subtitle, message, and details fields.                |

## Troubleshooting

* **Modal does not appear:** confirm `ModalManager.Instance` is not null — the subsystem must exist on the RuntimeManager prefab and runtime must be initialized.
* **Modal appears behind other UI:** check canvas sort order; ModalManager typically uses a high-priority canvas.
* **`ShowModal(string modalKey)` returns null:** ensure a `ModalEntry` with the matching key exists in the ModalManager component's `modalPrefabs` list in the Inspector.
* **Loading overlay persists:** call `RemoveLoading(title)` or `HideFullScreenLoading()` explicitly — overlays are not auto-removed.

## Related

* [Shared modals](/shared/modals) — product-specific modal types (text input, selection, progress)
* [RuntimeManager](/core/runtime-manager) — `ModalManager` is a child subsystem
* [Localization](/core/localization) — modals with localized text

## Unity Editor

<Frame caption="ModalManager — modal prefabs and settings">
  <img src="https://mintcdn.com/ptmolcateknologinusantara/jus_XMBZ8O0U_mpA/images/features/core/modal-manager-inspector.png?fit=max&auto=format&n=jus_XMBZ8O0U_mpA&q=85&s=ec38e486d8f301809ae14a3b0daa6cd9" alt="Modal Manager Inspector" width="715" height="720" data-path="images/features/core/modal-manager-inspector.png" />
</Frame>
