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

36 lines
738 B
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::GetChild
按索引返回当前对象的直接子对象。
```cpp
GameObject* GetChild(size_t index) const;
```
## 行为说明
当前实现只访问 `m_children`
-`index < m_children.size()`,返回对应子对象指针
- 否则返回 `nullptr`
它不会递归搜索孙节点或更深层子树。
`tests/Components/test_game_object.cpp` 已验证:
- 有效索引会返回正确子对象
- 越界索引会返回 `nullptr`
## 参数
- `index` - 直接子对象索引,基于当前 `m_children` 顺序。
## 返回值
- `GameObject*` - 对应直接子对象;越界时返回 `nullptr`
## 相关文档
- [GetChildCount](GetChildCount.md)
- [GetChildren](GetChildren.md)
- [SetParent](SetParent.md)