Author : Timo Naskali

The [Init] attribute can be added to MonoBehaviour<T…> derived types, or initializer types, to configure default settings related to initialization and the drawing of the Init section in the Inspector. using Sisus.Init; using UnityEngine; // Set Enabled to false, to disable NullArgumentGuard, hide the Init section in the Inspector, // and disable WaitForServices. This is ..

Read more

Issue You have a component that derives from MonoBehaviour<T…> or implements IInitializable<T…>, but you don’t want the Init section to be drawn in the Inspector. One possible reason for this could be that the component only needs to receive Init arguments when it is being initialized at runtime using AddComponent, but never when it is ..

Read more

Cross-scene GameObject and component references can be assigned into Init fields of client components that have an initializer. To assign a cross-scene reference, open multiple scenes in the Editor, and drag-and-drop a GameObject from a different scene into the Init field of the client component. This will make Init(args) automatically generate a unique Cross-Scene Id ..

Read more

What is a Value Provider? Value providers are a highly flexible system that can be used to provide Init arguments dynamically at runtime. Value providers are any objects that implement IValueProvider<TValue> or IValueByTypeProvider (or their asynchronous counterparts, IValueProviderAsync<TValue> or IValueByTypeProviderAsync). Use Cases There are a lot of possible use cases for value providers – here ..

Read more

Issue Due to a limitation with Unity’s serialization system, embedded value providers cannot be serialized directly as part of prefab assets. Solution 1: Create Asset You can get around this limitation by adding the [CreateAssetMenu] attribute to your value provider, and creating assets to back them. You can then drag-and-drop the value provider assets into ..

Read more

Problem You have a base class that depends on some services. You want to create a class that derives from that base class, which depends on some additional services on top of the ones that the base class does. class Base : MonoBehaviour<A, B> { // The base class depends on some services A a; ..

Read more

Represents an object that can provide values of requested types on demand. A scriptable object or component that implements the IValueByTypeProvider interface can be assigned to an Initializer field, if IValueByTypeProvider.CanProvideValue returns true when provided the type of the field and a reference to the initializer. During initialization the Initializer will request the Init argument ..

Read more

Issue Init(args) only supports passing a maximum of twelve arguments to a component that derives from MonoBehaviour<T…> or implements IInitializable<T…> during its initialization. What can you do if you have a legacy class that depends on more than twelve external objects, and you want to refactor the class to derive from MonoBehaviour<T…> and receive those ..

Read more

When you register a global or a local service, you will always have to specify – either implicitly or explicitly – one or more defining types for it. In the below example, the Logger class is configured to be a global service with the defining types Logger and ILogger, by explicitly specifying the types in ..

Read more

Services Component The Services component can be used to register multiple asset and scene based services accessible to select clients. Registering Services Using The Services Component You can attach the Services component to any GameObject using the Add Component menu. Assigning Services Add a new item to the Provides Services list. Drag-and-drop the Object you ..

Read more