第 2 课2026.09.02
理解 Actor 的位置和组件附着关系。
第 2 课:根组件与场景组件
- 日期:2026-09-02
- 课程序号:第 2 课
- 知识点:ActorComponent、SceneComponent 与 RootComponent
用途
理解 Actor 的位置和组件附着关系。
核心概念
- ActorComponent 提供行为,本身没有场景变换。
- SceneComponent 在此基础上支持变换与附着;Actor 的根场景组件决定 Actor 的变换。
最小代码或操作示例
text
1. 在编辑器中新建 Actor 蓝图 BP_LessonActor 并打开。
2. 在 Components 面板添加 Scene 组件,命名 LessonRoot。
3. 将 LessonRoot 拖到 DefaultSceneRoot 上,使它替换默认根。
4. 添加 Cube(Static Mesh 组件),确认它位于 LessonRoot 下。
5. 设置 Cube 的相对位置 X=100,编译并把蓝图放入关卡。
6. 移动关卡中的 Actor,观察 Cube 跟随根组件移动。3~5 分钟练习
保持 Cube 相对 X=100,把 Actor 世界位置 X 改为 200(无旋转、单位缩放),预测 Cube 世界 X。
参考答案
text
Actor 世界 X:200
Cube 相对 X:100
Cube 世界 X:300
前提:父级无旋转,缩放为 1。与上一课的联系
上一课在 Actor 的 BeginPlay 中执行逻辑;本课补齐承载 Actor 空间变换的组件结构。