Actor类
2023年11月5日 2023年11月17日
虚幻C++基础类型,能放置到世界场景中的物体,具有相同的基类AActor。
所有能添加到世界场景中的物体都可称作Actor,如几何体,特效,声音。Actor对象有无实体均可。
可视化需要USceneComponent组件,模型需要UStaticMeshComponent组件。
可以在虚幻编辑器中往关卡添加Actor对象,也可以在代码中动态生成Actor对象。
Actor对象由各种Component组成,所有组件可以根据需求进行组装,方便重用。
AActor
头文件
UE_5.1/Engine/Source/Runtime/Engine/Classes/GameFrameWork/Actor.h
派生关系
AActor
^
UObject
^
UObjectBaseUtility
构成
- | |
---|---|
构造函数 | |
BeginPlay | 出现在场景中 |
Tick | 每秒更新 |
AActor::AttachToComponent
将Actor附加到可变换组件的挂载点
声明
1// ** 2// * Attaches the RootComponent of this Actor to the supplied component, optionally at a named socket. It is not valid to call this on components that are not Registered. 3// * @param Parent Parent to attach to. 4// * @param AttachmentRules How to handle transforms and welding when attaching. 5// * @param SocketName Optional socket to attach to on the parent. 6// * 7void AttachToComponent(USceneComponent* Parent, const FAttachmentTransformRules& AttachmentRules, FName SocketName = NAME_None);
参数
- | |
---|---|
Parent | 目标, 可变换组件 |
AttachmentRules | 挂载规则 |
SocketName | 挂载点名字 |
从属关系
AActor::SetOwner
public
设置上级
1// * 2// * Set the owner of this Actor, used primarily for network replication. 3// * @param NewOwner The Actor who takes over ownership of this Actor 4// * 5UFUNCTION(BlueprintCallable, Category=Actor) 6virtual void SetOwner( AActor* NewOwner );
AActor::GetOwner
public
访问上级
1// Get the owner of this Actor, used primarily for network replication 2UFUNCTION(BlueprintCallable, Category=Actor) 3AActor* GetOwner() const;
AActor::GetOwner<T>
public
访问上级
1// Templated version of GetOwner(), will return nullptr if cast fails 2template< class T > 3T* GetOwner() const 4{ 5 return Cast<T>(GetOwner()); 6}