Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AddComponent

Adds a component to the game object and registers an undo operation for this action.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor

AddComponent(GameObject, Type)

Adds a component to the game object and registers an undo operation for this action.
public static Component AddComponent(GameObject gameObject, Type type)

Parameters

gameObject

The game object you want to add the component to.

type

The type of component you want to add.

Returns

Type

Description

ComponentThe newly added component.

Remarks

If the undo is performed, the newly added component will be destroyed.

AddComponent<T>(GameObject)

Generic version.
public static T AddComponent<T>(GameObject gameObject) where T : Component

Parameters

gameObject

The game object you want to add the component to.

Returns

Type

Description

TThe newly added component.