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

1.0 KiB

GameObject::GetTransform

返回当前对象的内建 TransformComponent

该方法当前提供两个公开重载:

TransformComponent* GetTransform();
const TransformComponent* GetTransform() const;

行为说明

两个重载都直接返回底层 m_transform 指针。

按当前对象模型:

  • 每个 GameObject 构造时都会创建一个 TransformComponent
  • AddComponent<TransformComponent>() 也只是返回这同一份实例
  • RemoveComponent() 不允许移除它

因此在正常存活期内,这个接口应始终返回非空指针。

为什么它不是普通组件查询的简单别名

虽然 GetComponent 也可能返回 TransformComponent,但 GetTransform() 更明确:

  • 它直接表达“我要对象的内建 Transform”
  • 不受模板匹配与搜索顺序歧义影响
  • 对编辑器、脚本桥接和空间变换代码更可读

相关文档