class GameObject

book_4_sparkGenerated
code_blocksInput

Description

An object in the scene. Functionality is added using Components. A GameObject has a transform, which explains its position, rotation and scale, relative to its parent. It also has a name, and can be enabled or disabled. When disabled, the GameObject is still in the scene, but the components don't tick and are all disabled.

Members

Static Members

Member NameSummary
CloneCreate a unique copy of the GameObject
GetPrefabGet the GameObject of a prefab from file path
JsonReadRead JSON data into a GameObject
JsonWriteWrite GameObject data to JSON

Instance Members

Member NameSummary
CloneCreate a unique copy of the GameObject
IsDescendantReturns true if the passed in object is a descendant of ours
IsAncestorReturns true if the passed in object is an ancestor
AddSiblingAdd a sibling GameObject
SetParentSet the parent GameObject
MakeNameUniqueEnsure the GameObject's name is unique
GetAllObjectsGet all GameObjects
EditLogEdit log (obsolete)
GetBoundsThis is slow, and somewhat inaccurate. Don't call it every frame!
GetLocalBoundsThis is slow, and somewhat inaccurate. Don't call it every frame!
GetNextSiblingGet the GameObject after us
DestroyDestroy this object. Will actually be destroyed at the start of the next frame.
DestroyImmediateDestroy this object immediately. Calling this might cause some problems if functions are expecting the object to still exist, so it's not always a good idea.
ClearDestroy all components and child objects
AddComponentAdd a component to this GameObject
GetOrAddComponentAdd a component to this GameObject
GetComponentGet a component on this GameObject
GetComponentsGet components on this GameObject
GetComponentsInChildrenGet components on this GameObject and on descendant GameObjects
GetComponentInChildrenGet component on this GameObject or on descendant GameObjects
GetComponentsInParentGet components on this GameObject and on ancestor GameObjects
GetComponentInParentGet component on this GameObject and on ancestor GameObjects
NetworkSpawnSpawn on the network. If you have permission to spawn entities, this will spawn on everyone else's clients and you will be the owner.
SetPrefabSourceSet the prefab source for this GameObject
BreakFromPrefabWe are cloned from a prefab. Stop that.
UpdateFromPrefabUpdate this GameObject from its prefab
SerializeSerialize this GameObject to JSON
DeserializeDeserialize JSON data into this GameObject
PlaySoundPlay this sound on this GameObject. The sound will follow the position of the GameObject.
StopAllSoundsStop any sounds playing on this GameObject

Properties

Property NameSummary
SceneThe scene that this GameObject is in.
TransformOur position relative to our parent, or the scene if we don't have any parent.
NameThe GameObject's name is usually used for debugging, and for finding it in the scene.
IsRootReturns true if this is a root object. Root objects are parented to the scene.
RootReturn the root GameObject. The root is the object that is parented to the scene - which could very much be this object.
EnabledTokenThis token is cancelled when the GameObject ceases to exist, or is disabled
ComponentsAccess components on this GameObject
EnabledIs this gameobject enabled?
ParentThe parent GameObject
ChildrenThe child GameObjects
ActiveIs this gameobject active. For it to be active, it needs to be enabled, all of its ancestors need to be enabled, and it needs to be in a scene.
DebugOverlayAllows drawing of temporary debug shapes and text in the scene
IsValidTrue if the GameObject is not destroyed
IsDestroyedReturn true if this object is destroyed. This will also return true if the object is marked to be destroyed soon.
FlagsGameObject flags
HasGimzoHandleUse HasGizmoHandle
HasGizmoHandleIndicates if the GameObject has a gizmo handle
IdThe unique identifier for this GameObject
LocalTransformThe local transform of the game object.
LocalPositionThe local position of the game object.
LocalRotationThe local rotation of the game object.
LocalScaleThe local scale of the game object.
IsProxyTrue if this is a networked object and is owned by another client. This means that we're not controlling this object, so shouldn't try to move it or anything.
IsNetworkRootIf true then this object is the root of a networked object.
NetworkedOBSOLETE: Use NetworkMode instead.
NetworkModeHow should this object be networked to other clients? By default, a GameObject will be networked as part of the GameObject.Scene snapshot.
NetworkInterpolationWhether or not our networked transform will be interpolated. This property will only be synchronized for a root network object.
NetworkAccess network information for this GameObject.
PrefabInstanceSourceThe source of the prefab instance
IsPrefabInstanceIndicates if this GameObject is an instance of a prefab
IsPrefabInstanceRootIndicates if this GameObject is the root of a prefab instance
TagsAccess tags for this GameObject
WorldTransformThe world transform of the game object.
WorldPositionThe world position of the game object.
WorldRotationThe world rotation of the game object.
WorldScaleThe world scale of the game object.