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 an IArgs<T…> interface makes a promise to receive arguments that have been injected for them during their initialization process using the InitArgs.TryGet method.
It is recommended that components retrieve initialization arguments that have been provided to them during their Awake event in most cases. The Awake event has the benefit of always only being executed once, and occurring on the main thread after the deserialization process has already finished.
The OnEnable event is another viable option, in cases where you want components to reacquire their dependencies every time they become active and enabled.
It is also possible to retrieve global services registered using the [Service] attribute, or manually via Service.Set, in a a parameterless constructor or OnAfterDeserialize method if you pass Context.Constructor or Context.OnAfterDeserialize to the InitArgs.TryGet method. However it is important to understand that these can get executed on background threads, and the constructor gets called before the deserialization process occurs, which means that if you were to assign initialization arguments into any serialized fields, they could get overridden during the deserialization process.
The Start event function is not considered to be part of the initialization process, as it only only gets executed after a slight delay.
If an Object that implements IArgs<T…> but does not receive the arguments that were passed to it, then an InitArgumentsNotReceivedException typically gets thrown. However, if the Object implements IInitializable<T…> the arguments can be injected through the Init method, even if the client fails to receive the arguments independently, and in this case no exception will be thrown.
Note: The Awake event function does not get called for components on inactive GameObjects. Because of this it is advisable for component classes to implement IInitializable<T…> and not just IArgs<T…> in most cases.