Init(args)
Scripting Reference
Loading...
Searching...
No Matches

◆ AddComponent< TComponent, TArgument >() [2/2]

static void Sisus.Init.AddComponentExtensions.AddComponent< TComponent, TArgument > ( [DisallowNull] this GameObject gameObject,
out TComponent component,
TArgument argument )
static

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

The argument should either be received by the added component during its initialization (such during the Awake event) or if the component class implements the IInitializable<TArgument> interface the argument can be provided using the Init function immediately after initialization has finished (before the Start event function).

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

Template Parameters
TComponentType of the component to add.
TArgumentType of the argument passed to the component's Init function.
Parameters
gameObjectThe GameObject to which the component is added.
componentWhen this method returns, contains the component of type TComponent that was added to the gameObject . This parameter is passed uninitialized.
argumentThe argument passed to the component's Init function.
Exceptions
ArgumentNullExceptionThrown if this GameObject is null.
InitArgumentsNotReceivedExceptionThrown if TComponent class does not implement IInitializable<TArgument> and did not manually handle receiving the provided arguments.
Type Constraints
TComponent :MonoBehaviour 
TComponent :IArgs<TArgument>