Version: 2022.3
Language : English
Create components with scripts
Tags

Deactivate GameObjects

To temporarily remove a GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
from your sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
, you can mark the GameObject as inactive.

To do this, navigate to the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary
window and clear the checkbox to the left of the GameObject’s name. The names of deactivated GameObjects appear faded in the Hierarchy window.

To deactivate a GameObject through script, use the SetActive method. To see if an object is active or inactive, check the activeSelf property.

If you deactivate a GameObject, coroutines attached to it are stopped.

Deactivate a parent GameObject

If you deactivate a parent GameObject, you also deactivate all of its child GameObjects because the deactivation overrides the activeSelf setting on all child GameObjects. The child GameObjects return to their original state when you reactivate the parent.

To know if a child GameObject is active in your scene, use the activeInHierarchy property.

Note: The activeSelf property is not always accurate if you check a child GameObject because even if it is set to active, you might have set one of its parent GameObjects to inactive.

The selected GameObject (Cube) is set as active, but remains inactive until you set its parent GameObject to active.
The selected GameObject (Cube) is set as active, but remains inactive until you set its parent GameObject to active.
Create components with scripts
Tags
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961