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 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; }