UE4基础:Gameplay框架(三)Actor 类(5月27日 更新)
2020-06-02 04:15
471 查看
本文是老王学习UE4的笔记,如有错误敬请指正
文章目录
概述
AActor继承于
UObject是所有可以放置到场景中的对象的基类。Gameplay框架的核心基类之一。
UCLASS声明
AActor的
UCLASS已经声明了
BlueprintType, Blueprintable这两个属性都可以传递给子类。
UCLASS(BlueprintType, Blueprintable, config=Engine, meta=(ShortTooltip="An Actor is an object that can be placed or spawned in the world.")) class ENGINE_API AActor : public UObject { GENERATED_BODY() ... }
生命周期
protected: virtual void BeginPlay() override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; public: virtual void Tick(float DeltaTime) override;
Tick相当于Unity中的
Update,UE4中的
Tick可以通过
PrimaryActorTick.bCanEverTick来开关。
virtual void Tick( float DeltaSeconds ); FORCEINLINE bool CanEverTick() const { return PrimaryActorTick.bCanEverTick; } UPROPERTY(EditDefaultsOnly, Category=Tick) struct FActorTickFunction PrimaryActorTick;
获取ULevel和UGameInstance
UWorld在UObject中就可以获取
- 获取所属
ULevel
ULevel* GetLevel() const;
- 获取
UGameInstance
class UGameInstance* GetGameInstance() const;
Actor的名字
//定义在基类UObjectBaseUtility中 public: FORCEINLINE FString GetName() const { return GetFName().ToString(); }
和组件相关的一些内容
AActor有3个管理组件的容器
OwnedComponents
:集合InstanceComponents
:数组BlueprintCreatedComponents
数组
另外还有一个重要的
RootComponent组件
- 它是所有其它组件的根组件
- 它一定是
USceneComponent
类型即带有变换的组件
private: TSet<UActorComponent*> OwnedComponents; UPROPERTY(Instanced) TArray<UActorComponent*> InstanceComponents; public: UPROPERTY(TextExportTransient, NonTransactional) TArray<UActorComponent*> BlueprintCreatedComponents; protected: UPROPERTY(BlueprintGetter=K2_GetRootComponent, Category="Utilities|Transformation") USceneComponent* RootComponent; public: FORCEINLINE USceneComponent* GetRootComponent() const { return RootComponent; }
和场景中的AActor树相关的一些内容
private: UPROPERTY(ReplicatedUsing=OnRep_Owner) AActor* Owner; public: UPROPERTY(Transient) TArray<AActor*> Children; UFUNCTION(BlueprintCallable, Category=Actor) AActor* GetOwner() const; UFUNCTION(BlueprintCallable, Category=Actor) virtual void SetOwner( AActor* NewOwner );
和蓝图中的AActor树相关的一些内容
UFUNCTION(BlueprintCallable, Category="Actor") AActor* GetParentActor() const; UFUNCTION(BlueprintCallable, Category="Actor") UChildActorComponent* GetParentComponent() const;
一些奇葩的地方
AActor
应该是抽象层次很高的类,里面竟然有关于伤害的定义- 竟然还引用了子类
APawn
和ACharacter
UInputComponent
也应该是在APawn
层级才有交集
/** * Whether this actor can take damage. Must be true for damage events (e.g. ReceiveDamage()) to be called. * @see https://www.unrealengine.com/blog/damage-in-ue4 * @see TakeDamage(), ReceiveDamage() */ UPROPERTY(EditAnywhere, BlueprintReadWrite, SaveGame, Replicated, Category=Actor, meta=(AllowPrivateAccess="true")) uint8 bCanBeDamaged:1; private: /** Pawn responsible for damage and other gameplay events caused by this actor. */ UPROPERTY(BlueprintReadWrite, ReplicatedUsing=OnRep_Instigator, meta=(ExposeOnSpawn=true, AllowPrivateAccess=true), Category=Actor) class APawn* Instigator; UPROPERTY(DuplicateTransient) class UInputComponent* InputComponent; /** * Return true if the given Pawn can be "based" on this actor (ie walk on it). * @param Pawn - The pawn that wants to be based on this actor */ virtual bool CanBeBaseForCharacter(class APawn* Pawn) const; /** * Apply damage to this actor. * @see https://www.unrealengine.com/blog/damage-in-ue4 * @param DamageAmount How much damage to apply * @param DamageEvent Data package that fully describes the damage received. * @param EventInstigator The Controller responsible for the damage. * @param DamageCauser The Actor that directly caused the damage (e.g. the projectile that exploded, the rock that landed on you) * @return The amount of damage actually applied. */ virtual float TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, AActor* DamageCauser); protected: virtual float InternalTakeRadialDamage(float Damage, struct FRadialDamageEvent const& RadialDamageEvent, class AController* EventInstigator, AActor* DamageCauser); virtual float InternalTakePointDamage(float Damage, struct FPointDamageEvent const& PointDamageEvent, class AController* EventInstigator, AActor* DamageCauser);
相关文章推荐
- UE4基础:Gameplay框架(二)UObject类(5月28日 更新)
- Wcf通讯基础框架方案(五)——更新通知
- Houdini技术体系 基础管线(三) :UE4以选择区域的方式对地形做生成和更新 上篇
- UE4入门学习3:GamePlay框架
- UE4基础:自定义GameInstance(5月30日 更新)
- Unity dll 热更新 基础框架
- Unity3d dll 热更新 基础框架
- (从零到一)五子棋博弈算法——基础框架(不定期更新)
- 《连载 | 物联网框架ServerSuperIO教程》- 17.集成Golden实时数据库,高并发保存测点数据。附:3.4 发布与版本更新说明。
- Java基础知识强化之集合框架笔记69:Collections类之ArrayList存储自自定义对象并排序的案例
- Yii2.0框架基础--数据查询之AR类方法where()
- 迭代(一)搭建框架基础体系
- Sping框架总结(核心原理+基础入门)
- javascript基础教程第8版---第5章窗口与框架---学习笔记
- Android-->完整项目 核心框架推荐(不定期更新)
- HTML基础知识四( 内嵌入式框架、 滑动字幕、多媒体元素、CSS)
- android stdudio 更新最新SDK 可用框架 用百分比view
- 汇编语言基础之七- 框架指针的省略(FPO)
- 【SSH三大框架】Struts2基础第一篇:编写第一个Struts2程序
- 永辉彩食鲜开源基础框架 csx-bsf-all【开源】【原创】