# GameObject

### Description

**GameObject** is a [scene](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/scene) intractable object.&#x20;

GameObject's can represent players, shapes and scenery. In more easy way, GameObject is set of components, to add for that object real functionality.

### Properties

|                                               |                                                                                                                                                                 |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">transform</mark>     | Direct access to [Transform](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/transform) of this <mark style="color:red;">GameObject</mark>. |
| <mark style="color:red;">scene</mark>         | The [scene](https://danil-dukhovenko.gitbook.io/force/force-editor/gameplay/scenes) to which this <mark style="color:red;">GameObject</mark> belongs to.        |
| <mark style="color:red;">tag</mark>           | The `tag` of this <mark style="color:red;">GameObject</mark>.                                                                                                   |
| <mark style="color:red;">activeInScene</mark> | Is this <mark style="color:red;">GameObject</mark> is active in [scene](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/scene)?             |

### Inherited Properties

|                                      |                                                            |
| ------------------------------------ | ---------------------------------------------------------- |
| <mark style="color:red;">name</mark> | `Name` of this <mark style="color:red;">GameObject</mark>. |

### Constructors

|                                                                                      |                                                                                                                                                                        |
| ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">GameObject</mark>                                           | Create new <mark style="color:red;">GameObject</mark> and attach [Transform](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/transform) component. |
| <mark style="color:red;">GameObject(string name)</mark>                              | Create new <mark style="color:red;">GameObject</mark> with `name` and  [Transform](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/transform).     |
| <mark style="color:red;">GameObject(string name, params string\[] components)</mark> | Create new <mark style="color:red;">GameObject</mark> and attach array of `components` by `name`.                                                                      |
| <mark style="color:red;">GameObject(params string\[] components)</mark>              | Create new <mark style="color:red;">GameObject</mark> and attach array of `components` by `name`.                                                                      |
| <mark style="color:red;">GameObject(string name, params Type\[] components)</mark>   | Create new <mark style="color:red;">GameObject</mark> and attach array of `components` by type.                                                                        |
| <mark style="color:red;">GameObject(params Type\[] components)</mark>                | Create new <mark style="color:red;">GameObject</mark> and attach array of `components` by type.                                                                        |

### Static Methods

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                                                                                                                                                                                                                                                                |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">CreateGameObject</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | <p>Create a copy of <mark style="color:red;">GameObject</mark> with the same components.</p><p><br>If you want modify object components data and that was affected on runtime scene throw script code use <code>MonoScript.CreateGameObject(other).</code></p> |
| <mark style="color:red;">CreateGameObject(PrimitiveType primitiveType)</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Compares two gameobjects.                                                                                                                                                                                                                                      |
| <mark style="color:red;">Compare</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | Create new <mark style="color:red;">GameObject</mark> and attach array of `components` by `name`.                                                                                                                                                              |
| <mark style="color:red;">Destroy</mark>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | <p>Destroyes <a href="component">Component</a> or <a href="gameobject">GameObject</a> or <a href="asset">Asset</a>. If Component, GameObject, Asset is null this method does nothing.</p><p>                                                                   |
| <br>If obj is type of <strong>GameObject</strong> it will be destoryed after <code>OnUpdate()</code> loop is finished. If object attached to <a href="monoscript">MonoScript</a>, object calls <code>OnDestroy()</code> method to free all user resources, detach object from script and remove all components. If <strong>GameObject</strong> is null this method does nothing.<br><br>If obj is type of <strong>Component</strong> then immediately detach Component from assisated instance of <strong>GameObject</strong>. If component is <strong>MonoScript</strong>,<br>object calls <code>OnDestroy()</code> method-event to free all user resources. If <strong>Component</strong> is null this method does nothing.</p><p></p><p>If obj is type of <strong>Asset</strong> (<a href="texture2d">Texture2D</a>, <a href="audioclip">AudioClip</a>, <a href="font">Font</a>, etc) it immidiatly removes it if possible.<br> |                                                                                                                                                                                                                                                                |

</p> |

### Methods

|                                                                                              |                                                                                                                                                                                                                                                                                                                                                   |
| -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">CompareTag</mark>                                                   | Has the game object input `tag`?                                                                                                                                                                                                                                                                                                                  |
| <mark style="color:red;">CompareName</mark>                                                  | Has the game object input `name`?                                                                                                                                                                                                                                                                                                                 |
| <mark style="color:red;">Compare</mark>                                                      | Compares two components.                                                                                                                                                                                                                                                                                                                          |
| <mark style="color:red;">AddComponent</mark>                                                 | Adds new component to this [GameObject](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/gameobject), and return `this` component.                                                                                                                                                                                             |
| <mark style="color:red;">AddComponent\<T></mark>                                             | <p>\[Generic Version] </p><p>Adds new component with type <code>T</code> to this <a href="gameobject">GameObject</a>, and return <code>this</code> component.</p>                                                                                                                                                                                 |
| <mark style="color:red;">AddComponent(Type componentType)</mark>                             | <p>\[Type Version] </p><p>Adds new component with <code>Type</code> to this <a href="gameobject">GameObject</a>, and return <code>this</code> component.</p>                                                                                                                                                                                      |
| <mark style="color:red;">HasComponent</mark>                                                 | <p>\[Type Version]</p><p>Returns <code>true</code> if given component attached to this <a href="gameobject">GameObject</a> otherwise <code>false</code>. Use this if you want fastest performance because it just recall native function.</p>                                                                                                     |
| <mark style="color:red;">HasComponent\<T></mark>                                             | <p>\[Generic Version]</p><p>Returns <code>true</code> if component atleast has one attached component of given type <code>T</code> to this <a href="gameobject">GameObject</a> otherwise <code>false</code>.</p>                                                                                                                                  |
| <mark style="color:red;">HasComponent(string componentType)</mark>                           | <p>\[String Version]</p><p>Returns component of given <code>type</code> from this component <a href="gameobject">GameObject</a>, it component exist there will returns it, if that component not exist, will add new component of given type to this GameObject.</p>                                                                              |
| <mark style="color:red;">GetComponent</mark>                                                 | <p>\[Type Version]</p><p>Returns the given component of the given <code>type</code> if it attached to this <a href="gameobject">GameObject</a>. This method will return the first component with this type that he found.</p>                                                                                                                     |
| <mark style="color:red;">GetComponent(string componentType)</mark>                           | <p>\[String version]</p><p>Returns the given component if it attached to this <a href="gameobject">GameObject</a>.</p>                                                                                                                                                                                                                            |
| <mark style="color:red;">GetComponent\<T></mark>                                             | <p>\[Generic Version]</p><p>Returns the given component of type <code>T</code> if it attached to this <a href="gameobject">GameObject</a>. If component not exist then this return <code>null</code> instance. </p>                                                                                                                               |
| <mark style="color:red;">GetOrAddComponent</mark>                                            | <p>\[Type Version]</p><p>Returns component of given <code>type</code> from this component <a href="gameobject">GameObject</a>, it component exist t component not exist, will add new component of given type to this GameObject.</p>                                                                                                             |
| <mark style="color:red;">GetOrAddComponent\<T></mark>                                        | <p>\[Generic Version]</p><p>Returns component of <code>T</code> from this component <a href="gameobject">GameObject</a>, it component exist there will returns it, if that component not exist, will add new component of given type to this GameObject. </p>                                                                                     |
| <mark style="color:red;">GetOrAddComponent(string componentType)</mark>                      | <p>\[String Version]</p><p>Returns component of given <code>type</code> from this component <a href="gameobject">GameObject</a>, it component exist there will returns it, if that component not exist, will add new component of given type to this GameObject. </p>                                                                             |
| <mark style="color:red;">GetComponents</mark>                                                | Return the array with all given components in [GameObject](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/gameobject).                                                                                                                                                                                                       |
| <mark style="color:red;">TryGetComponent(Type componentType, out Component component)</mark> | <p>\[Type Version]</p><p>Tries to retrive the component of given <code>type</code> from component <a href="gameobject">GameObject</a>. This method will returns <code>true</code> and output not-null component if it exist. If component was not found, this returns <code>false</code> and set output component to <code>null</code>.</p>       |
| <mark style="color:red;">TryGetComponent\<T>(out Component component)</mark>                 | <p>\[Generic Version]</p><p>Tries to retrive the component of given type <code>T</code> from component <a href="gameobject">GameObject</a>. This method will returns <code>true</code> and output not-null component if it exist. If component was not found, this returns <code>false</code> and set output component to <code>null</code>. </p> |
| <mark style="color:red;">TryGetComponent(string componentType)</mark>                        | <p>\[String Version]</p><p>Tries to retrive the component of given <code>type</code> from component <a href="gameobject">GameObject</a>. This method will returns <code>true</code> and output not-null component if it exist. If component was not found, this returns <code>false</code> and set output component to <code>null</code>. </p>    |
| <mark style="color:red;">GetUUID</mark>                                                      | Returns the **Unique ID** of this [GameObject](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/gameobject).                                                                                                                                                                                                                   |
| <mark style="color:red;">SetActiveInScene</mark>                                             | Sets the object active `state` in [scene](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/scene). If object is active that it will rendered and perfom any physics behaviour on it.                                                                                                                                           |
| <mark style="color:red;">SetActiveInEditor</mark>                                            | Sets the object active `state` in editor. If object is active in editor it can be visualized in editor if not it will be hidden.                                                                                                                                                                                                                  |
| <mark style="color:red;">IsActiveInScene</mark>                                              | Returns `true` if object is active in scene.                                                                                                                                                                                                                                                                                                      |
| <mark style="color:red;">IsActiveInEditor</mark>                                             | Returns `true` of object is active in editor.                                                                                                                                                                                                                                                                                                     |
| <mark style="color:red;">ToString</mark>                                                     | The `string` representation of [GameObject](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/gameobject).                                                                                                                                                                                                                      |

### Inherited Methods

|                                             |                                                                                                                                                                                                                         |
| ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">GetObjectID</mark> | Returns the `ID` of current object. `ID` is unique only per one runtime session. Each sessions of runtime/play mode will change the `ID` of object. Not recommend equal object by `ID` if this not one runtime session. |

### See Also

[Component](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/component), [MonoScript](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/monoscript), [Transform](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/transform)
