I’ve commented the code itself for brevity. This is my current understanding, please feel free to comment if you believe this is incorrect in any way:
The header file
#pragma once // Preprocessor directive to ensure this file is included only once
// A series of include files
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PositionReport.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) // An Unreal macro of some sort .. unsure of its exact function
class BUILDINGESCAPE_API UPositionReport : public UActorComponent // Our class named UPositionReport inherited from UActorComponent
{
GENERATED_BODY() // Again some Unreal macro presumably handling internal engine requirements for added components
public:
// Sets default values for this component's properties
UPositionReport(); // Our class's constructor
protected:
// Called when the game starts
virtual void BeginPlay() override;
/*
The BeginPlay function called from the engine when the game starts. virtual implies this function can
be over ridden by the same function in an inherited class based on this one. override implies this
function overrides the same named virtual function in the base class UActorComponent
*/
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
/*
The TickComponent function with passed arguments called again from
the engine once every frame. virtual implies this function can be over ridden by the same function in
an inherited class based on this one. override implies this function overrides the same named virtual
function in the base class UActorComponent
*/
};
and the cpp file
#include "PositionReport.h" // Include the appropriate header file for the class
// Sets default values for this component's properties
UPositionReport::UPositionReport() // The constructor definition
{
// 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; // Self explanatory from the associated comments
// ...
}
// Called when the game starts
void UPositionReport::BeginPlay() // Place any component code required to execute when the game starts in here
{
Super::BeginPlay(); // Calls the base class's function of the same name
// ...
}
// Called every frame
void UPositionReport::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
// Place any component code to be executed every frame in here
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); // Call this base class function passing the stated arguments.
// ...
}