I’m currently familiarizing myself with UE4’s plugin system.
One project is to create an actor and add it to a level. It prints the current FPS every five seconds.
I’ve written the plugin and the actor. I’ve enabled the plugin and turned off both the blueprint filter and placeable filter (even though everything is placeable by default).
For some reason though the actor is not showing up in the class viewer which means I can’t place it inside the level.
Here is the code for the actor
FPSPrinterActor.h
#pragma once
#include "FPSPrinterActor.generated.h"
UCLASS()
class AFPSPrinterActor: public AActor
{
GENERATED_UCLASS_BODY()
float Timer;
float FramesGoneBy;
virtual void BeginPlay() OVERRIDE;
virtual void TickActor(float DeltaSeconds, ELevelTick TickType, FActorTickFunction& ThisTickFunction) OVERRIDE;
};
FPSPrinterActor.cpp
#include "FPSPrinterPrivatePCH.h"
AFPSPrinterActor::AFPSPrinterActor(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
Timer = 0.0f;
FramesGoneBy = 0.0f;
}
void AFPSPrinterActor::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Hello World!"));
}
}
void AFPSPrinterActor::TickActor(float DeltaSeconds, ELevelTick TickType, FActorTickFunction& ThisTickFunction)
{
Super::TickActor(DeltaSeconds, TickType, ThisTickFunction);
FramesGoneBy++;
Timer += DeltaSeconds;
if (Timer >= 5.0f)
{
Timer = 0.0f;
FramesGoneBy = 0.0f;
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Current FPS:"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(static_cast<int>(FramesGoneBy / Timer)));
}
}
}