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

◆ Instantiate< TObject, TArgument >() [2/4]

static TObject Sisus.Init.InstantiateExtensions.Instantiate< TObject, TArgument > ( [DisallowNull] this TObject original,
TArgument argument,
[AllowNull] Transform parent,
bool instantiateInWorldSpace = false )
static

Clones the original TObject , theinitializes it with the given argument and then returns the clone.

The argument should either be received by the created Object during its initialization (such as during the Awake event) or if the Object 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 original object is a Component in an inactive GameObject, while if the gameObject is inactive the argument will be received during the Awake event function.

Template Parameters
TObjectType of the Object that is being cloned.
TArgumentType of the argument used during initialization of the clone.
Parameters
originalOriginal TObject to clone.
argumentThe argument used during initialization of the clone.
parentParent that will be assigned to the new object.
instantiateInWorldSpaceWhen you assign a parent Object, pass true to position the new object directly in world space. Pass false to set the object’s position relative to its new parent.
Returns
The cloned TObject .
Exceptions
ArgumentNullExceptionThrown if original is null.
InitArgumentsNotReceivedExceptionThrown if TObject class does not implement IInitializable<TArgument> and did not manually handle receiving the provided arguments during its initialization.
Type Constraints
TObject :Object 
TObject :IArgs<TArgument>