Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Component

Base class for everything that can be attached to a GameObject.
Read time 4 minutesLast updated 3 days ago

Definition

  • Type: Class
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
  • Inherits from: Object
public class Component : Object

Remarks

Note that you don't instantiate the
Component
class directly. Instead, you write code in MonoBehaviour scripts, which inherit from
Component
, and attach the scripts to a GameObject. Additional Resources: ScriptableObject as a way to create scripts that do not attach to any GameObject.

Properties

Property

Description

gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
transformHandleThe TransformHandle of this GameObject.

Methods

Method

Description

BroadcastMessageCalls the method named
methodName
on every MonoBehaviour in this game object or any of its children.
CompareTagChecks the GameObject's tag against the defined
tag
.
GetComponentThe string-based version of this method.
GetComponentInChildrenThis is the non-generic version of this method.
GetComponentIndexGets the index of the component on its parent GameObject.
GetComponentInParentThe non-generic version of this method.
GetComponentsThe non-generic version of this method.
GetComponentsInChildrenThe non-generic version of this method.
GetComponentsInParentThe non-generic version of this method.
SendMessageCalls the method named
methodName
on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named
methodName
on every MonoBehaviour in this game object and on every ancestor of the behaviour.
TryGetComponentThe non-generic version of this method.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.