![]() |
Init(args)
Scripting Reference
|
◆ Init()
Initializes the object with an object that it depends on. You can think of the Init method 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 the end of initialization (after Awake and OnEnable but before Start) when an instance is being created using InstantiateExtensions.Instantiate<TObject, TArgument>(TObject, TArgument) or AddComponentExtensions.AddComponent<TComponent, TArgument>(GameObject, TArgument). It is also possible for the object to receive the argument at an earlier stage of its initialization process, such as in the constructor or during the Awake event, using InitArgs.TryGet<TArgument>.
Implemented in Sisus.Init.MonoBehaviour< TArgument >, Sisus.Init.Requires< TArgument >, Sisus.Init.ScriptableObject< TArgument >, and Sisus.Init.StateMachineBehaviour< TArgument >. |