UIPrefabLoader<TKey> is a generic spawner for UI-flavored prefabs keyed by an arbitrary type (commonly string). Lives in com.cupkekgames.luna runtime; the concrete UIPrefabLoaderString is the most common entry point.

It extends the base PrefabLoader<TKey> (in com.cupkekgames.core) and adds Luna-specific UI integration: FadeOutDestroy(key, duration) — fade out all spawned instances of a key via FadeUIElement before destroying the GameObject. Useful for modals, toasts, popups, etc.

When to use it

Reach for UIPrefabLoaderString when you want to:

  • Spawn a UI prefab by string key at runtime, with auto-tracking of all live instances
  • Fade out + destroy on close (instead of cutting the GameObject)
  • Reuse the same loader instance across scenes (the demo Manager prefab calls DontDestroyOnLoad)

The flagship sample uses it for the news/notification modal in GameUiHub.OpenNotificationHistory():

csharp
private static void OpenNotificationHistory() { UIPrefabLoaderString.Instance?.Instantiate("NotificationModal"); }

API

csharp
public abstract class UIPrefabLoader<TKey> : PrefabLoader<TKey> { public void FadeOutDestroy(TKey key, float duration = 0.5f); } public class UIPrefabLoaderString : UIPrefabLoader<string> { public static UIPrefabLoaderString Instance { get; } }

Inherited from PrefabLoader<TKey> (in core):

MemberReturnsDescription
Instantiate(TKey key)GameObjectSpawn a new instance of the prefab registered to key. Tracks the instance internally.
GetInstances(TKey key)List<GameObject>All currently-live instances of key.
ContainsKey(TKey key)boolWhether the loader has a prefab registered for key.
event OnInstanceDestroyedEventHandler<TKey>Fired when any instance is destroyed (manually or via FadeOutDestroy).

Setup

UIPrefabLoaderString extends MonoBehaviour (via KeyValueDatabaseMono<TKey, GameObject>). Drop it on a GameObject in your boot scene, configure the _searchFolder (FolderReference) so it auto-populates the prefab database from a folder of UI prefab assets, and assign string keys per-prefab in the inspector.

The LunaUI sample's LunaUIManager.prefab already includes a UIPrefabLoaderString instance — use it as a starting point.

Variants

VariantPackageUse case
UIPrefabLoader<TKey>com.cupkekgames.lunaBase — folder-scan prefabs (no Addressables)
UIPrefabLoaderAddressable<TKey>com.cupkekgames.addressablesAddressables-keyed loading + caching
UIPrefabLoaderAddressableStringcom.cupkekgames.addressablesConcrete string-keyed addressables variant

The non-addressable chain lives in Luna so projects without Addressables installed can still use the prefab-loader pattern. See PrefabLoader for the addressable-flavored variants.

See also

Settings

Theme

Light

Contrast

Material

Dark

Dim

Material Dark

System

Sidebar(Light & Contrast only)

Light
Dark

Font Family

DM Sans

Wix

Inclusive Sans

AR One Sans

Direction

LTR
RTL