Init(args)
Scripting Reference

◆ AddComponent< TComponent, TFirstArgument, TSecondArgument, TThirdArgument, TFourthArgument >() [1/2]

static TComponent Sisus.Init.GameObjectExtensions.AddComponent< TComponent, TFirstArgument, TSecondArgument, TThirdArgument, TFourthArgument > ( [NotNull] this GameObject  gameObject,
TFirstArgument  firstArgument,
TSecondArgument  secondArgument,
TThirdArgument  thirdArgument,
TFourthArgument  fourthArgument 
)
static

Adds a component of type TComponent to the gameObject and initializes the component using the provided arguments.

Arguments should either be received by the added component during its initialization (such during the Awake event function or in the constructor) or if the component class implements the IInitializable<TFirstArgument, TSecondArgument, TThirdArgument, TFourthArgument> interface the arguments can be provided using the Init function immediately after initialization has finished (before the Start event function).

For classes deriving from MonoBehaviour<TFirstArgument, TSecondArgument, TThirdArgument, TFourthArgument> the latter method will be used in cases where the gameObject is inactive, while if the the gameObject is inactive the arguments will be received during the Awake event function.

Template Parameters
TComponentType of the component to add.
TFirstArgumentType of the first argument passed to the component's Init function.
TSecondArgumentType of the second argument passed to the component's Init function.
TThirdArgumentType of third argument which is passed to the component's Init function.
TFourthArgumentType of fourth argument which is passed to the component's Init function.
Parameters
gameObjectThe GameObject to which the component is added.
firstArgumentThe first argument passed to the component's Init function.
secondArgumentThe second argument passed to the component's Init function.
thirdArgumentThe third argument passed to the component's Init function.
fourthArgumentThe fourth argument passed to the component's Init function.
Returns
The added component.
Exceptions
ArgumentNullExceptionThrown if this GameObject is null.
InitArgumentsNotReceivedExceptionThrown if TComponent class does not implement IInitializable<TFirstArgument, TSecondArgument, TThirdArgument, TFourthArgument> and did not manually handle receiving the provided arguments.
Type Constraints
TComponent :MonoBehaviour 
TComponent :IArgs 
TComponent :TFirstArgument 
TComponent :TSecondArgument 
TComponent :TThirdArgument 
TComponent :TFourthArgument