// TestComponent.h
UCLASS()
class PROJECTREPLICA_API UTestComponent : public UActorComponent
{
GENERATED_BODY()
public:
UTestComponent();
public:
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
public:
UFUNCTION(BlueprintCallable, Category = "Test")
void ActivateTimer();
private:
FTimerHandle Timer;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "test", meta = (AllowPrivateAccess = "true"))
bool bActivateTimer;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "test", meta = (AllowPrivateAccess = "true"))
float Countdown;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "test", meta = (AllowPrivateAccess = "true"))
float TickCountdown;
};
// TestComponent.cpp
UTestComponent::UTestComponent()
{
PrimaryComponentTick.bCanEverTick = true;
bActivateTimer = false;
Countdown = 0.0f;
TickCountdown = 0.0f;
}
void UTestComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if(bActivateTimer)
{
PR_LOG_SCREEN_INFO(0, "TickCountdown: %f", TickCountdown);
PR_LOG_SCREEN_INFO(1, "Countdown: %f", Countdown);
TickCountdown += DeltaTime;
if(TickCountdown > 10.0f)
{
PR_LOG_SCREEN("Finish TickCountdown");
}
}
}
void UTestComponent::ActivateTimer()
{
PR_LOG_SCREEN("activate");
if(IsValid(GetOwner()) == true)
{
if(bActivateTimer == false)
{
bActivateTimer = true;
}
GetOwner()->GetWorldTimerManager().SetTimer(Timer, FTimerDelegate::CreateLambda([&]()
{
Countdown++;
if(Countdown > 10.0f)
{
GetOwner()->GetWorldTimerManager().ClearTimer(Timer);
PR_LOG_SCREEN("Finish Countdown");
}
}), 1.0f, true);
}
}
Tick은 GlobalTimeDilation에 영향을 받지 않아 TimeStop 기능을 구현할 때 유용하게 쓰일것으로 보인다.
'Unreal Engine > etc.' 카테고리의 다른 글
[Unreal Engine etc.] UActorComponent::OnRegister (0) | 2023.12.20 |
---|---|
[Unreal Engine etc.] C++에서 CineCameraComponent 사용 (0) | 2023.11.10 |
[Unreal Engine 4 etc.] AddMovementInput 관련 (0) | 2022.09.16 |
[Unreal Engine 4 etc.] 특정 액터를 향해 화살표를 회전시키기 (0) | 2022.08.16 |
[Unreal Engine 4 etc.] 서로 다른 클래스 간의 통신을 위한 4가지 방법 (0) | 2021.04.21 |