Category : 03. Features

Init(args) has been designed with inversion of control in mind and aims to make it as easy as possible to work with interfaces instead of specific classes in Unity. One pain point when using interfaces in Unity is that checking them for null can be problematic. This is because in addition to being actually null, ..

Read more

A base class for MonoBehaviours that depend on receiving upto five objects in their constructor during initialization. For example the following Player class depends on an object that implements the IInputManager interface and an object of type Camera. public class Player : ConstructorBehaviour<IInputManager, Camera> When you create a component that inherits from one of the ..

Read more

Sometimes you may want to make use of read-only fields or get-only properties in your components and scriptable objects. Read-only members make your data immutable and as such result in code that is less prone to errors and fully thread safe without needing any complicated thread locking. The issue is that you can’t pass any ..

Read more

The generic GameObject structs are builder 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

The Wrapper class is a component that acts as a simple wrapper for a plain old class object. It makes it easy to take a plain old class object and attach it to a GameObject and have it receive callbacks during any Unity events you care about such as Update or OnDestroy as well as ..

Read more

When a component that derives from MonoBehaviour<T> and has the InitOnResetAttribute is first added 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<T> struct is similar to the Initializer class, but instead of it allowing you to specify all the Init arguments for a client, the Any<T> struct lets you specify just one argument. For example, if you wanted to make it possible to assign any class that implements the IPlayer interface using the inspector, you ..

Read more

A major benefit of injecting dependencies to your classes through the Init method is that it makes it easy to decouple your components from specific implementations when you use interfaces instead of specific classes as your argument types. The list of arguments that the Init method accepts also makes it very clear what other objects ..

Read more