Runs your Screens, Popups & Overlays. One root, one way back, one queue.
UIDirector is a navigation layer for uGUI. Views are prefabs under one persistent root, opened by typed keys that carry their argument and result types, and ShowAsync completes with a result that says how the view ended instead of throwing. Screens keep a history stack, popups share a backdrop, system overlays block input, one back rule decides what a back press does, and an optional priority queue presents notices one at a time.
| Unity | 6000.0 or newer. |
| UniTask | Required. Install it before this package; a package installed from a git URL cannot declare it as a dependency. |
com.unity.ugui 2.0.0 |
Required. It is declared as a dependency, so a git install brings it in when your manifest does not list it. It includes TextMesh Pro, which the samples use. |
Addressables (com.unity.addressables) |
Optional, for views loaded by address. |
| DOTween | Optional, for TweenTransition and your own transitions on DOTween. |
| Zenject or Extenject | Optional, for injecting services into views. |
Input System (com.unity.inputsystem) |
Optional. BackInput reads the back key from it when it is installed and active, and from the legacy input manager otherwise. |
Install UniTask first. In the Package Manager open the + menu, choose Add package from git URL (newer editors label it Install package from git URL) and enter:
https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask
UniTask documents its other install routes in its own README. Then add UIDirector the same way:
https://github.com/ecanakli/UnityUIDirector.git#v0.1.1
Or add both lines to the dependencies of Packages/manifest.json (the order does not matter):
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
"com.ecanakli.uidirector": "https://github.com/ecanakli/UnityUIDirector.git#v0.1.1"
Always install a tag. Without #v0.1.1 the install tracks the default branch.
- Your code is in assembly definitions. Reference
Ecanakli.UIDirectorandUniTask. AddEcanakli.UIDirector.Addressablesto useAddressablesViewProviderfrom code,Ecanakli.UIDirector.DOTween(withDOTween.dlland the define constraint, see DOTween) to useTweenTransition, andEcanakli.UIDirector.DependencyInjection.ZenjectplusZenjectforNavigatorInstaller. Every type is in the namespaceEcanakli.UIDirectorexceptNavigatorInstaller(Ecanakli.UIDirector.DependencyInjection). Code outside assembly definitions needs no reference. - Addressables. The integration compiles by itself when
com.unity.addressablesis installed. There is nothing to switch on. See Assets and Addressables. - DOTween. The integration compiles when the
DOTWEENdefine is present, which DOTween's own setup panel sets, or when a UPM package namedcom.demigiant.dotweenis installed. If neither is true but the DOTween assembly is in the project, chooseTools/UIDirector/DOTween Integrationonce. See DOTween. - Zenject under
Assets/. ChooseTools/UIDirector/Zenject Integrationonce; it sets a scripting define on every build target, so commitProjectSettingsafterwards. Extenject as a UPM package, 9.0.0 or newer: the integration turns itself on. See Zenject.
Six steps. Every block of code below is copied from the Basic Usage sample (see Samples), which compiles. The code is the scenario of its Settings screen: it asks "Reset settings" ("All settings return to their defaults.") in a confirm popup and acts on the answer.
The blocks leave out the using lines. Add the ones a file needs: Ecanakli.UIDirector for every
package type, Cysharp.Threading.Tasks where UniTask or Forget appears, System.Threading for
CancellationToken, TMPro for TMP_Text, and UnityEngine and UnityEngine.UI for SerializeField
and Button. The sample's own files sit in the namespace Ecanakli.UIDirector.Samples.BasicUsage, which
already reaches Ecanakli.UIDirector; your files need the using line. The argument types the blocks
pass around (ConfirmArgs, ItemArgs, RenameArgs, ToastArgs) are plain structs you write yourself.
In the sample they are in ViewArgs.cs:
/// <summary>What the confirm popup shows.</summary>
public readonly struct ConfirmArgs
{
public readonly string Title;
public readonly string Message;
public ConfirmArgs(string title, string message)
{
Title = title;
Message = message;
}
}
/// <summary>Which item the detail screen shows.</summary>
public readonly struct ItemArgs
{
public readonly string ItemId;
public ItemArgs(string itemId)
{
ItemId = itemId;
}
}
/// <summary>The item to rename and its current title.</summary>
public readonly struct RenameArgs
{
public readonly string ItemId;
public readonly string CurrentTitle;
public RenameArgs(string itemId, string currentTitle)
{
ItemId = itemId;
CurrentTitle = currentTitle;
}
}
/// <summary>The one line a toast shows.</summary>
public readonly struct ToastArgs
{
public readonly string Message;
public ToastArgs(string message)
{
Message = message;
}
}
Choose GameObject > UI > UIDirector Root. It creates a canvas with a ViewRoot and a BackInput,
and an EventSystem when the scene has none. Without an EventSystem views show but receive no
clicks (UIDIRECTOR116). With Initialize On Awake
left on, the root initializes itself in Awake with the three default layers and ViewRoot.Navigator
is ready from then on. The Basic Usage sample turns Initialize On Awake off and initializes the root
in code, because its toast row sits on a layer that only code can declare (step 5). Details are in
Root canvas.
Create a catalog with Assets > Create > UIDirector/View Catalog, add one row per view prefab (an id,
the prefab, the layer it opens on) and drag the catalog into the Catalogs list of the root. A view
prefab has a ViewHost and one view component on its root. Then give every row a typed key, in one
static class marked [ViewKeys]:
[ViewKeys]
public static class AppViews
{
public static readonly ViewKey<NoArgs, NoResult> Home = ViewKey.Create("home");
public static readonly ViewKey<NoArgs, NoResult> Library = ViewKey.Create("library");
public static readonly ViewKey<ItemArgs, NoResult> ItemDetail = ViewKey.Create<ItemArgs>("item-detail");
public static readonly ViewKey<NoArgs, NoResult> Settings = ViewKey.Create("settings");
public static readonly ViewKey<ConfirmArgs, bool> Confirm = ViewKey.Create<ConfirmArgs, bool>("confirm");
public static readonly ViewKey<RenameArgs, string> Rename = ViewKey.Create<RenameArgs, string>("rename");
public static readonly ViewKey<NoArgs, NoResult> Saving = ViewKey.Create("saving");
public static readonly ViewKey<ToastArgs, NoResult> Toast = ViewKey.Create<ToastArgs>("toast");
}
Confirm takes a ConfirmArgs and answers with a bool; Home takes nothing and answers nothing.
The compiler checks what you pass in and what you read out. Run Tools/UIDirector/Validate Catalogs
to check keys and rows against each other before you press Play. See
Catalogs and keys.
A view derives from ViewBehaviour<TArgs, TResult>. OnOpen receives the arguments and a scope; what
you bind to the scope is removed when the open ends, so there is no OnDisable and no
RemoveListener. Complete(value) closes the popup and answers:
public sealed class ConfirmView : ViewBehaviour<ConfirmArgs, bool>
{
[SerializeField] private TMP_Text _title;
[SerializeField] private TMP_Text _message;
[SerializeField] private Button _accept;
[SerializeField] private Button _decline;
protected override void OnOpen(ConfirmArgs args, ViewScope open)
{
_title.text = args.Title;
_message.text = args.Message;
// The package removes both listeners when this open ends.
open.Bind(_accept.onClick, Accept);
open.Bind(_decline.onClick, Refuse);
}
private void Accept()
{
Complete(true);
}
private void Refuse()
{
Complete(false);
}
}
The popup's row sits on the built-in popups layer: modal, with a shared backdrop, and it takes back.
See View authoring and
Popups and backdrop.
ShowAsync opens a view and completes with a ViewResult<bool>. It does not throw for anything that
happens to the view: a back press, a tap on the backdrop, a refusal and an ended owner all arrive as a
result without a value. The token passed with every open is its owner; when it is cancelled the view
ends. Here the owner is the token of the screen's open scope, so the popup cannot outlive the screen:
The Reset button starts the check in the screen's open scope, which runs it with the scope's token:
private void OnResetClicked()
{
OpenScope.Run(ConfirmResetAsync);
}
private async UniTask ConfirmResetAsync(CancellationToken ct)
{
// The owner is this screen's scope token: the popup cannot outlive the screen.
var answer = await Navigator.ShowAsync(
AppViews.Confirm,
new ConfirmArgs("Reset settings", "All settings return to their defaults."),
ct,
new OpenOptions { Source = "settings.reset", RejectWhenBusy = true });
// Refused at once instead of waiting behind a view that is still opening.
if (answer.Rejected == RejectReason.Busy)
{
_status.text = "Busy, try again.";
return;
}
// Back, backdrop and a closed screen all end with no value, so this line also guards the screen.
if (!answer.HasValue || !answer.Value)
return;
_settings.ResetToDefaults();
_status.text = "Settings were reset.";
// The toast outlives this screen, so the root owns it.
Navigator.Open(
AppViews.Toast,
new ToastArgs("Settings were reset."),
Navigator.RootToken,
new OpenOptions { Source = "settings.reset" });
}
Always check HasValue before you read Value: for a bool result the default is false, which looks
like an answer. The last call is the other way to open a view: Open returns a handle at once and does
not wait. The root owns the toast because it must outlive the screen that asked for it. More in
Opening and results.
The toast row of the catalog sits on a layer named toasts. The three default layers do not include
it, so the sample declares it in code:
// Above the system layer, no history, no back and no input shield: a toast never blocks a tap.
public static readonly ViewLayer Toasts = new ViewLayer("toasts", 3, ViewLayerRules.None);
A layer declared in code reaches the root through ViewRootSetup.ExtraLayers, which only Initialize
accepts. That is why the sample turns Initialize On Awake off and initializes the root in its own
Awake. Turn it off on your root too before you call Initialize: a root that already initialized
itself throws InvalidOperationException on a second initialization. Without this call the toast row is refused at registration
(UIDIRECTOR109) and opening the toast ends as not
shown. The other ViewRootSetup members are covered in
Add a layer of your own:
_viewRoot.Initialize(new ViewRootSetup
{
Inject = InjectServices,
ErrorHandler = OnViewError,
ExtraLayers = new[] { AppLayers.Toasts }
});
_navigator = _viewRoot.Navigator;
Then open the first screen. The root's token as owner means the screen ends only when the root does:
private void Start()
{
// Owned by the root, so Home ends only when the root does.
_navigator.Open(AppViews.Home, _navigator.RootToken, new OpenOptions { Source = "boot" });
}
_navigator is ViewRoot.Navigator. A screen opens on the screens layer, which is a stack and the
back history; opening an id that is already in the stack returns to it. See
Navigation and back.
Back() is the single back rule. It returns true when something handled the press and false when
nothing did:
// The other screens use a ViewButton set to Back; this one shows the call.
private void GoBack() => Navigator.Back();
BackInput, which the root menu added, calls Back() on the Escape key once the root is initialized. On the bottom screen Back()
returns false and closes nothing; BackInput then raises Unhandled, and the game decides. The sample
listens and asks to quit with the same confirm popup:
// No removal needed: the bootstrap and the root live and die together.
_backInput.Unhandled.AddListener(OnBackUnhandled);
private void OnBackUnhandled()
{
// A Unity event cannot await; the quit answer is read inside.
ConfirmQuitAsync().Forget();
}
private async UniTaskVoid ConfirmQuitAsync()
{
var answer = await _navigator.ShowAsync(
AppViews.Confirm,
new ConfirmArgs("Quit", "Close the application?"),
_navigator.RootToken,
new OpenOptions { Source = "back.root" });
if (!answer.HasValue || !answer.Value)
return;
A yes then calls Application.Quit(), and in the editor it stops Play Mode.
Press Play and open Window > UIDirector to watch the layers, the requests and the input shield live.
To see every request in the Console, add an observer: the sample's ViewEventLog prints one [views]
line per event (see Events and analytics). A message
tagged UIDIRECTOR1xx is explained in Troubleshooting.
Import them from the Package Manager: select UIDirector, open the Samples tab and press
Import. Each sample has its own README with the setup steps and a list of things to try. Every
sample scene has no Event System on purpose, because the right input module depends on your project's
input handling; the sample creates one when Play starts. Basic Usage, Queue Usage, Addressables Usage,
DOTween Usage and Zenject Usage all use TextMesh Pro, so import its Essential Resources once with
Window > TextMeshPro > Import TMP Essential Resources; the texts stay blank until then.
| Sample | Needs | Shows |
|---|---|---|
| Basic Usage | The core only, TextMesh Pro Essential Resources | A confirm popup with a result, three screens with back, a system overlay, a custom layer and transition, events and errors |
| Queue Usage | The core only, TextMesh Pro Essential Resources | A priority queue for popups: startup notices, a gate that denies, a hold while a flow runs, a feature catalog added at run time |
| Addressables Usage | com.unity.addressables, and the two prefabs marked addressable (a menu item does it) |
Views loaded by address, a preload lease and trimming kept instances |
| DOTween Usage | DOTween, with the integration active | TweenTransition on a popup and a custom transition built on DOTween |
| Zenject Usage | Zenject or Extenject with the integration active, and a Scene Context you add yourself | The navigator bound in a SceneContext and views that receive injections |
The same grouping is on the documentation home.
Start here
- Concepts: the root, layers, keys, requests, outcomes, owners and scopes
- Root canvas: the root, its fields,
ViewRootSetup, the sorting band, your own layers - Catalogs and keys: rows, typed keys, adding a catalog at run time, the validator
- View authoring: writing a view, its hooks, scopes, kept instances
- Opening and results:
OpenandShowAsync, handles, results, owners,CloseAll - FAQ: short answers to the first questions
Guides
- Navigation and back: the history stack,
CloseTo,Back(),BackPolicy,BackInput - Popups and backdrop: modal popups, the backdrop, the input shield,
RejectWhenBusy - System overlays: blocking overlays around a piece of work
- Transitions: the built-in transitions and writing your own
- Queue: priorities, gates, holds and a feature that adds its own catalog
- Events and analytics: the observer interface and every event
- Input and platform: the EventSystem, the shield, double taps,
HoldInput, the back button - Migration: moving a project that has a UI manager of its own, one view at a time
Integrations
- DOTween:
TweenTransitionand kill-safe custom transitions - Assets and Addressables: views by address, preload, keep and trim, your own provider
- Zenject:
NavigatorInstallerand injection into views
Reference
- API reference: every public type and member as signatures
- Diagnostics: console lines, the UIDirector window, the read-out, the error handler, the validator
- Troubleshooting: one section per
UIDIRECTOR1xxid, then symptoms - Performance: what is guaranteed about cost and which test holds it
- Threading: what throws off the main thread and what is posted to it
- Limitations: what the package does not do and its provisional defaults
Design
- Architecture: why the package is shaped this way
- ADR-001 Outcomes as data
- ADR-002 Strict serialization
- ADR-003 Begin-only hooks and scopes
- ADR-004 The queue sits above the navigator
- ADR-005 Token owners
For AI tools, llms.txt holds a summary, the rules that bite and a one-line description of every page in reading order, and llms-full.txt is the whole documentation in one file.
- Version 0.1.1. See the changelog.
- Main thread only. Opening, registering and queueing throw on another thread; a few stop-type calls are posted to the main thread. See Threading.
- uGUI only, with a
Screen Space - OverlayorScreen Space - Cameraroot. World-space UI and UI Toolkit are not supported. One root per application is the documented setup. - Diagnostics have stable ids,
UIDIRECTOR101toUIDIRECTOR126. Ids 101 to 120 and 126 are logged at run time in the editor and in development builds. Ids 121 to 124 come only from the catalog validator, and 125 from the validator and from the root when a catalog with a row whose id is empty or only whitespace is registered (that row is refused). Each has a section in Troubleshooting. - What the package deliberately leaves to the game is listed in Limitations.
MIT. See LICENSE.md.