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

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

static TObject Sisus.Init.InstantiateExtensions.Instantiate< TObject, TArgument > ( [DisallowNull] this TObject original,
TArgument argument,
Vector3 position,
Quaternion rotation,
[AllowNull] Transform parent )
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.

See also
Object.Instantiate
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.
positionThe position for the new instance.
parentParent that will be assigned to the new object.
rotationThe orientation of the new GameObject.
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>