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

38 lines
871 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::Find
按对象名称在全局 registry 中查找第一个匹配的 `GameObject`
```cpp
static GameObject* Find(const std::string& name);
```
## 行为说明
当前实现会遍历 `GameObject::GetGlobalRegistry()`,并检查:
```cpp
pair.second->GetName() == name
```
找到第一个匹配项后立即返回。
## 重要边界
- 查询范围是全局 registry不是某个 `Scene` 的局部子树
- 独立构造、未加入场景的对象默认不会被查到
- registry 底层是 `std::unordered_map`,因此“第一个匹配项”的顺序不构成稳定契约
## 参数
- `name` - 目标对象名。
## 返回值
- `GameObject*` - 找到时返回匹配对象;否则返回 `nullptr`
## 相关文档
- [GameObject](GameObject.md)
- [FindObjectsOfType](FindObjectsOfType.md)
- [FindGameObjectsWithTag](FindGameObjectsWithTag.md)