# GameObject::GetComponentInParent 沿父链向上查找第一个匹配组件。 ```cpp template T* GetComponentInParent(); ``` ## 搜索顺序 当前实现不会先检查当前对象自己,而是: 1. 先看当前对象是否存在父节点 2. 对父对象调用 [GetComponent](GetComponent.md) 3. 若父对象未命中,则继续递归向更高层父节点查询 因此它返回的是“最近祖先链上第一个匹配组件”。 ## 当前语义边界 - 搜索范围不包含当前对象自己 - 若父对象存在匹配项,就不会继续往更高祖先找 - 对宽类型查询,父对象的 `TransformComponent` 仍可能优先命中 ## 相关文档 - [GetComponent](GetComponent.md) - [GetParent](GetParent.md) - [GetComponentInChildren](GetComponentInChildren.md)