Files
XCEngine/docs/api/XCEngine/Components/GameObject/SetActive.md

41 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# GameObject::SetActive
设置对象自身的 `activeSelf` 状态,并在必要时重新传播层级有效激活态。
```cpp
void SetActive(bool active);
```
## 行为说明
当前实现会先比较新旧 `m_activeSelf`
- 如果值没有变化,直接返回
- 如果值变化,重新计算对象当前的 `active in hierarchy`
当“层级有效激活态”发生变化时,当前实现会:
- 对已启用的普通组件发送 `OnEnable()``OnDisable()`
- 把变化递归传播到子对象
## 重要边界
- 它改的是对象自己的 `activeSelf`,不是直接改父子层级
- 真正是否参与运行,还要结合 [IsActiveInHierarchy](IsActiveInHierarchy.md) 判断
- `TransformComponent` 不参与普通组件遍历,因此不会在这里收到 `OnEnable()` / `OnDisable()`
## 参数
- `active` - 新的 `activeSelf` 值。
## 返回值
- 无。
## 相关文档
- [GameObject](GameObject.md)
- [IsActive](IsActive.md)
- [IsActiveInHierarchy](IsActiveInHierarchy.md)
- [SetParent](SetParent.md)