Init(args)
Scripting Reference

◆ Init() [1/5]

void Sisus.Init.IInitializable< TFirstArgument, TSecondArgument, TThirdArgument, TFourthArgument, TFifthArgument >.Init ( TArgument  argument)

Initializes the object with an object that it depends on.

You can think of the Init function as a parameterized constructor alternative for Object-derived classes.

For classes that derive from MonoBehaviour<TArgument> Init gets called during the Awake event when the instance is being loaded at runtime and during the Reset event when the script is added to a GameObject in edit mode. If the GameObject is inactive causing the Awake event to never get fired, then the Init method is called immediately after the object has been created.

For classes that derive from ScriptableObject<TArgument> Init also gets called during the Awake event.

For other classes that implement IInitializable<TArgument> Init gets called automatically at the end of initialization (after Awake and OnEnable but before Start) when an instance is created using the ObjectExtensions.Instantiate<TObject, TArgument> or the GameObject.AddComponent function.

It is also possible for the initialized object to retrieve the argument at any earlier stage of its initialization process, such as in the constructor or during the Awake event, using InitArgs.TryGet<TArgument>. If the arguments are retrieved independently by the object during its initialization process like this, then the argument will not get injected to the object again separately through the Init method being called by the injection code.

Parameters
argumentArgument used during initialization of the component.

Implemented in Sisus.Init.ScriptableObject< TFirstArgument, TSecondArgument, TThirdArgument, TFourthArgument, TFifthArgument >, and Sisus.Init.MonoBehaviour< TFirstArgument, TSecondArgument, TThirdArgument, TFourthArgument, TFifthArgument >.