Class GameObjectExtensions
UnityEngine.GameObject Based Extension Methods
Inheritance
Namespace: GDX
Syntax
[VisualScriptingCompatible((short)2)]
public static class GameObjectExtensions
Methods
| Improve this Doc View SourceDestroyChildren(GameObject, Boolean, Boolean)
Destroy child UnityEngine.GameObject.
Declaration
public static void DestroyChildren(this GameObject targetGameObject, bool deactivateBeforeDestroy = true, bool destroyInactive = true)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | targetGameObject | The parent UnityEngine.GameObject to look at. |
System.Boolean | deactivateBeforeDestroy | Should the |
System.Boolean | destroyInactive | Should inactive UnityEngine.GameObject be destroyed as well? |
Exceptions
Type | Condition |
---|---|
UnsupportedRuntimeException | Not supported on DOTS Runtime. |
GetFirstComponentInChildrenComplex<T>(GameObject, Boolean, Boolean, Int32)
A slightly more complex version of UnityEngine.Component.GetComponentInChildren<T>(System.Boolean) which allows for different hinted search options.
Declaration
public static T GetFirstComponentInChildrenComplex<T>(this GameObject targetGameObject, bool includeInactive = false, bool lookInChildrenFirst = false, int maxLevelsOfRecursion = -1)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | targetGameObject | The target UnityEngine.GameObject to use as the base for the search. |
System.Boolean | includeInactive | Include inactive child UnityEngine.GameObjects when looking for the UnityEngine.Component. |
System.Boolean | lookInChildrenFirst | Should children UnityEngine.GameObject be searched before the
|
System.Int32 | maxLevelsOfRecursion | The maximum levels of recursion when looking for a UnityEngine.Component, -1 for infinite recursion. |
Returns
Type | Description |
---|---|
T | The first found UnityEngine.Component. |
Type Parameters
Name | Description |
---|---|
T | The target UnityEngine.Component type that is being looked for. |
Remarks
If the maxLevelsOfRecursion
is set to 1; this will search the
targetGameObject
and its immediate children only.
The internal UnityEngine.Component.GetComponentInChildren<T>(System.Boolean) has optimizations internally in engine code which make it faster in different scenarios.
Exceptions
Type | Condition |
---|---|
UnsupportedRuntimeException | Not supported on DOTS Runtime. |
GetOrAddComponent<T>(GameObject)
Get a component by type from a targetGameObject
, if it is not found add and return it.
Declaration
public static T GetOrAddComponent<T>(this GameObject targetGameObject)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | targetGameObject | The UnityEngine.GameObject that we should query for the component. |
Returns
Type | Description |
---|---|
T | The component on the |
Type Parameters
Name | Description |
---|---|
T | The type of component. |
Remarks
Adding a component at runtime is a performance nightmare. Use with caution!
Exceptions
Type | Condition |
---|---|
UnsupportedRuntimeException | Not supported on DOTS Runtime. |
GetScenePath(GameObject)
Get an in scene path to the targetGameObject
.
Declaration
public static string GetScenePath(this GameObject targetGameObject)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | targetGameObject | The UnityEngine.GameObject which to derive a path from. |
Returns
Type | Description |
---|---|
System.String | A created path System.String. |
Exceptions
Type | Condition |
---|---|
UnsupportedRuntimeException | Not supported on DOTS Runtime. |