Author : Timo Naskali

Global Services Typically you can register a global service simply by adding the [Service] attribute directly to type of the service: [Service] public class SomeService { } Sometimes, however, you might want to create services from types defined inside third-party assets, in which case making any modifications to their source code could be out of ..

Read more

Init(args) comes bundled with several add-ons. They can all be found under Packages/Init(args)/Add-Ons in the Project window and installed by double-clicking their respective unity packages and selecting Import. Odin Contains SerializedMonoBehaviour<T…> base classes. Enables you to create components that are serialized by the Odin serializer like SerializedMonoBehaviour, and can automatically receive services during initialization like ..

Read more

The Preload Scene (also known as the Boostrap Scene) is a technique where you always launch your game from the same scene. This enables you, among other things, to place important global services into this scene, and ensure that they are always loaded before any other scene objects in the game. One big pain point ..

Read more

Null Argument Guard The Null Argument Guard is a feature that can automatically inform you about missing Init arguments that any of your components might have. The feature consists of three distinct parts: Inspector Warnings – Warnings shown in the Editor when you view a component containing missing Init arguments in the Inspector Window. Edit ..

Read more

References to GameObjects and components that are only instantiated at runtime can be assigned into Init fields of client components that have an initializer. To assign a reference to an yet-to-be-instantiated prefab instance, drag-and-drop a prefab asset from the Project window into the Init field of a client component in a scene, and select ‘Prefab Instance’ ..

Read more

Sometimes you might need to inject a different instance of the same service to every client that requests the service. This can be achieved in Init(args) using value providers: Create a class that implements IValueProvider<T>, where T is the concrete or defining type of your service. Implement IValueProvider<T>.Value in such a way, that a new ..

Read more

Types that contain generic type parameters can also be registered as global services by adding the [Service] attribute to them: using Sisus.Init; [Service] public class Logger<T> { public void Info(string message) => Debug.Log(typeof(T).Name + ” – ” + message); } When this is done, no instance of the global service is created automatically during initialization ..

Read more

Init(args) has built-in support for the Entity Component System (ECS). Systems You can register a system as a global service by adding the [Service] attribute to its type. This makes it possible for clients – including all other services that have the [Service] attribute – to receive the system automatically during their initialization. Containing World ..

Read more

The Service class contains methods that can be used to manually register service objects and retrieve them for clients. This is lower level API. You typically don’t need to use it directly, but should instead use the [Service] attribute, Service Tag and Services component to register services, and create a class that derives from MonoBehaviour<T…> ..

Read more

This page aims to answer what makes Init(args) different from other dependency injection solutions for Unity. Versatility Init(args) improves upon just using normal serialized fields (which is also a form of dependency injection) by introducing a lot more flexibility. Serialized fields don’t support the following use cases: Using services from different scenes or prefabs. Using ..

Read more