GameObject
A GameObject represents an object in the scene world. It contains a few different elements.
A GameObject represents an object in the scene world. It contains a few different elements.
Transform
Represents where the GameObject is in the scene. Its positioning, its rotation and its scale.
If it has a parent then its transform is held relative to them, so when their parent moves, so does the child.
Here's how you can interact with them in code
// Set world position
GameObject.WorldPosition = new Vector3( 100, 100, 100 );
// Set position relative to parent
GameObject.LocalPosition = new Vector3( 100, 100, 100 );
// Set world transform
GameObject.WorldTransform = new Transform( Vector3.Zero, new Angles( 90, 90, 180 ), 2.0f )
Tags
The GameObject's tags are used for multiple things. They're used to group physics objects to decide what should collide with each other. They can be used by cameras to decide which objects should and shouldn't render. And they can be used by programmers to do whatever they want.
if ( GameObject.Tags.Has( "enemy" ) )
{
GameObject.Destroy();
}
GameObject.Tags.Add( "enemy" );
GameObject.Tags.Set( "enemy", isEnemy );
GameObject.Tags.Remove( "enemy" );
Tags are inherited. If a parent has the tag, then so does the child. The only way to remove the tag from the child is to remove it from the parent.
Children
GameObject children are available via GameObject.Children. This is just a list of GameObjects.
We should really lock this down a bit more. Make it readonlylist or something.
Components
GameObjects implement functionality using Components.
Referenced API
Canonical API pages mentioned in this guide.
Euler angles. Unlike a Rotation, Euler angles can represent multiple revolutions (rotations) around an axis, but suffer from issues like gimbal lock and lack of a defined "up" vector. Use Rotation for most cases.
A struct containing a position, rotation and scale. This is commonly used in engine to describe entity position, bone position and scene object position.
A 3-dimentional vector. Typically represents a position, size, or direction in 3D space.
The Z component of this vector.
Represents a Quaternion rotation. Can be interpreted as a direction unit vector (x,y,z) + rotation around the direction vector (w) which represents the up direction. Unlike `Angles`, this cannot store multiple revolutions around an axis.
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.
No summary available.
Destroy this object. Will actually be destroyed at the start of the next frame.