Skip to content

Instantly share code, notes, and snippets.

@p30virus
Created October 13, 2024 23:47
Show Gist options
  • Select an option

  • Save p30virus/e797ea1a4884db9111e004d63b454940 to your computer and use it in GitHub Desktop.

Select an option

Save p30virus/e797ea1a4884db9111e004d63b454940 to your computer and use it in GitHub Desktop.
// Fill out your copyright notice in the Description page of Project Settings.
#include "TimerComponent.h"
#include "Logging/StructuredLog.h"
// Sets default values for this component's properties
UTimerComponent::UTimerComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UTimerComponent::BeginPlay()
{
Super::BeginPlay();
// ...
UE_LOGFMT(LogTemp, Log, "Set a timer...");
GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &ThisClass::TimerFunction, 5.f, true);
}
void UTimerComponent::TimerFunction()
{
UE_LOGFMT(LogTemp, Log, "This is the timer...");
}
// Called every frame
void UTimerComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "TimerComponent.generated.h"
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class TIMERTEST_API UTimerComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UTimerComponent();
protected:
// Called when the game starts
virtual void BeginPlay() override;
FTimerHandle TimerHandle;
UFUNCTION()
void TimerFunction();
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment