Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


TryInstantiate

Creates a new instance of the specified T.
Read time 1 minuteLast updated 10 days ago

Definition

  • Type: Method
  • Namespace: Unity.Properties
  • Assembly: UnityEngine.PropertiesModule

TryInstantiate<T>(T)

Creates a new instance of the specified
T
.
public static bool TryInstantiate<T>(out T instance)

Parameters

instance

T
When this method returns, contains the created instance, if type instantiation succeeded; otherwise, the default value for
T
.

Returns

Type

Description

bool
true
if a new instance of type
T
was created; otherwise,
false
.

TryInstantiate<T>(Type, T)

Tries to create a new instance of the given type type and returns it as
T
.
public static bool TryInstantiate<T>(Type derivedType, out T value)

Parameters

derivedType

The type we want to create a new instance of.

value

T
When this method returns, contains the created instance, if type instantiation succeeded; otherwise, the default value for
T
.

Returns

Type

Description

bool
true
if a new instance of the given type could be created.