Author : Timo Naskali

Classes that implement one of the generic IArgs<T…> interfaces can be provided with arguments during initialization (up to a maximum of twelve). Methods such as Instantiate<TObject, T…> and AddComponent<TComponent, T…> can only be used to create instances of classes that implement one of the IArgs<T…> interfaces. A contract to receive arguments Any object that implements ..

Read more

The generic GameObject structs are builders that can be used to initialize a GameObject and upto three components in a single line of code. If you want a GameObject with a single component to be build, initialize a new instance of the GameObject<T> struct and specify the type of the component you want attached to ..

Read more

The Find class is a utility class that helps in locating instances of objects from loaded scenes as well as assets from the project. It has been designed from the ground up to work well with interface types, making it easier to decouple your code from specific concrete classes. All methods in the Find class ..

Read more

The ScriptableWrapper class is a ScriptableObject that can act as a simple wrapper for a plain old class object. It makes it easy to take a plain old class object and serialize it as an asset in the project. Let’s say you had a plain old class called Settings: public class Settings { public float ..

Read more

Wrappers can be used to attach plain old C# objects to a GameObjects, have them receive callbacks during Unity events like Update and OnDestroy, and to start coroutines. Creating a Wrapper Let’s say you had a plain old C# class called Player: using System; using UnityEngine; [Serializable] public class Player { [SerializeField] private Id id; ..

Read more

To fully grasp the advantages that Init(args) can unlock, it’s essential to first understand a key design principle in software engineering: inversion of control. In a nutshell, inversion of control means that instead of classes independently retrieving the objects they need, those objects are provided to them by other classes. This approach comes with several ..

Read more

When a component that derives from MonoBehaviour<T> and has the InitOnResetAttribute is first attached to a GameObject in the editor, or when the user hits the Reset button in the Inspector’s context menu, the arguments accepted by the component are automatically gathered and passed to its Init function. This auto-initialization behaviour only occurs in edit ..

Read more

The Any<TValue> type can be used to create serialized fields into which you can assign any objects of the given type using the Inspector. The value can be of any type which Unity can serialize, using [SerializeField] or [SerializeReference], including: Plain-old C# class UnityEngine.Object An interface type You’ll be able to select any assignable value ..

Read more

What Are Initializers? Attaching an initializer to a client component gives you the ability to customize all its Init arguments using the Inspector window – with a lot of enhancements over what’s possible using Unity’s serialized fields by default. While registering global and local services makes it convenient to deliver the same service object to ..

Read more

The InitArgs class is the bridge through which initialization arguments are passed from the classes that create instances to the objects that are being created (called clients). Note that in most cases you don’t need to use InitArgs directly; all of the various methods provided for initializing instances with arguments already handle this for you ..

Read more