.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ExampleActor.generated.h"
UCLASS()
class YOUR_API AExampleActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AExampleActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void MyCustomFunctionTimed();
virtual void MyCustomFunctionTimed_Implementation();
};
cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "ExampleActor.h"
DECLARE_STATS_GROUP(TEXT("MyCustomFunctionTimed"), STATGROUP_CustomFunctions, STATCAT_Funk);
DECLARE_CYCLE_STAT(TEXT("MyCustomFunctionTimed"), STATGROUP_CustomFunctions, STATGROUP_StatSystem);
AExampleActor::AExampleActor()
{
PrimaryActorTick.bCanEverTick = true;
}
void AExampleActor::BeginPlay()
{
Super::BeginPlay();
}
void AExampleActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AExampleActor::MyCustomFunctionTimed_Implementation()
{
SCOPE_CYCLE_COUNTER(STATGROUP_CustomFunctions); // <==here is where you add a cycle counter
for (int32 i = 0; i < 200; i++) {
UE_LOG(LogTemp, Warning, TEXT("Doing work %s"), *FString::FromInt(i));
}
}
As you can see custom function shows up in the unreal insights.
Inside of the actor I just call the event via a timer to trigger it