UE4基礎:Gameplay框架(四)UActorComponent 類

  • UActorComponent派生自UObject
  • 它是所有“組件”的基類。
  • 只有AActor以及其派生類纔能有“組件”。

聲明

UCLASS(DefaultToInstanced, BlueprintType, abstract, meta=(ShortTooltip="An ActorComponent is a reusable component that can be added to any actor."), config=Engine)
class ENGINE_API UActorComponent : public UObject, public IInterface_AssetUserData
{
	GENERATED_BODY()
	...
}

生命週期


virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction);

virtual void BeginPlay();
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason);

virtual void OnRegister();
virtual void OnUnregister();

關於Tick


virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction);

UFUNCTION(BlueprintCallable, Category="Utilities")
virtual void SetComponentTickEnabled(bool bEnabled);

UFUNCTION(BlueprintCallable, Category="Utilities")
virtual bool IsComponentTickEnabled() const;

關於Tag

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Tags)
TArray<FName> ComponentTags;

UFUNCTION(BlueprintCallable, Category="Components")
bool ComponentHasTag(FName Tag) const;



關於Activate

UFUNCTION(BlueprintCallable, Category="Components|Activation", meta=(UnsafeDuringActorConstruction="true"))
virtual void Activate(bool bReset=false);

UFUNCTION(BlueprintCallable, Category="Components|Activation", meta=(UnsafeDuringActorConstruction="true"))
virtual void Deactivate();

UFUNCTION(BlueprintCallable, Category="Components|Activation", meta=(UnsafeDuringActorConstruction="true"))
virtual void SetActive(bool bNewActive, bool bReset=false);

UFUNCTION(BlueprintCallable, Category="Components|Activation", meta=(UnsafeDuringActorConstruction="true"))
bool IsActive() const { return bIsActive; }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章