Validate a GameObject or an asset

When a GameObject or an asset has scripts with injected members, its Inspector window displays a Selvage section at the top, with the number of members in each state. Select the section to expand it: it lists the members of each script, with the state of each member and its type, then the static members of its class, marked static. To list only the members in one state, select its count. Select several counts to combine them. The check reads your code and the provider list, and doesn't run your code, so you find a missing dependency in the Editor instead of as a null at runtime.

The Selvage section at the top of the Inspector window of the Player GameObject, expanded: settings is Guaranteed, and body, view and audioManager are May Be Supplied
ResultMeaning
GuaranteedA provider always gives the member a dependency.
May Be SuppliedA provider can give one, but whether it does is only known when the member is injected.
MissingNo provider can give the member a dependency. To fix it, add a provider for the type, or make the member Optional.

In Play mode, and while editing for a member with the EditMode option, the section displays the state of each member and the provider that gave its dependency. For more information, refer to Inspect injected members.

Read the reason for a result

The Validation tab of the Dependencies window lists each member with its result and the reason for it. To open it on a GameObject or an asset, select the Selvage button at the right of its Selvage section, then select Validation. To validate a script, perform the following steps:

  1. Go to Tools > Selvage > Dependencies.
  2. Select Validation.
  3. In the Project window, select the script.

The window follows the selection while it is open.

The Validation tab of the Dependencies window with the Player script selected: settings is Guaranteed, and body, view and audioManager are May Be Supplied

A row also indicates when the member needs the Async option, when its provider can revoke its dependency, and when the member is part of a dependency cycle or leads into one.

Find out where a dependency comes from

When a member receives an object you didn't expect, select Explain on its row. The explanation lists the providers in the order Selvage tries them, highlights the provider that gives the dependency, and indicates why each provider above it didn't. To have another provider give the dependency, move it up in the provider list.

Explain open on the settings member, listing the providers in order with the Asset Provider highlighted

Validate the whole project

To validate every class in the project that has injected members, select nothing, or select Whole Project. The tab lists the classes with a Missing member first, and counts the members in each state, as it does for a selection. The check covers the assemblies of your project and the Selvage demo, and skips the assemblies of Selvage itself and of Unity. It runs a little every frame, so the Editor stays usable while it runs, and stops when you cancel it. To validate only the scripts of a folder, select the folder in the Project window.

The Validation tab listing every class of the project that has injected members, with the counts and the toolbar

To list only some members, use the State and Options filters in the toolbar. For a description of each control, refer to Dependencies window reference.

Validate when you build or enter Play mode

The same check can run when you build and when you enter Play mode. To set it up, perform the following steps:

  1. Go to Edit > Project Settings > Selvage.
  2. In the Validation section, set Build Validation and Play Validation to Off, Warn or Block.

By default, a build with a Missing member is blocked, and entering Play mode isn't checked. When entering Play mode is blocked, select Show in Dependencies to list the members that blocked it. For more information, refer to Project Settings reference.

Require every member to be guaranteed

To treat every required member that isn't Guaranteed as Missing, enable Strict Validation in Edit > Project Settings > Selvage, or select Strict in the Validation tab. A project that passes has every required dependency proven in the Editor.

A component the member's class requires with [RequireComponent] is Guaranteed. For more information, refer to Guarantee a component on the member's GameObject.

The check can't see what your code provides while playing, such as an object you add to a registry, so members of that type are May Be Supplied. To have them count as Guaranteed, promise the type in any script of your project:

[assembly: Promise(typeof(IAudio))]

Then keep the promise: add the object before a member of its type is injected, for example from a method marked [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]. Any provider can keep it. When no provider has the dependency as a required member is injected, the member fails, and the error names the promise. On the member's row, Explain ends with the promise, after the providers.

A promise covers Play mode only. A member with the EditMode option is also injected while editing, so the promise doesn't make it Guaranteed.

When the dependency arrives later, set how long it may take, in seconds of real time from when the member is injected:

[assembly: Promise(typeof(ISaveData), WithinSeconds = 30)]

A member with the Async option then waits until a provider has one. A member with the Warm option receives it once a provider has one: at once if it's also Reactive, otherwise on its next Manual.Reinject call. The check reports the members with neither option. If no provider has one in time, a required member fails, and the error names the promise. While a member waits, the Live tab of the Dependencies window reads Waiting on a provider to have one. For a dependency whose arrival depends on the player, such as a login, use float.PositiveInfinity to wait without a limit. A scene object wakes the members waiting for it only when its Provide Tuning is Watched.