Even though he said don’t look at the header we need to because the cpp doesn’t make sense without it.
class BUILDINGESCAPE_API UPositionReport : public UActorComponent
This has something to with inheritance. Saying that UPositionReport is a new class that inherits from UActorComponent (maybe, I donno)
GENERATED_BODY()
I think this is a function that tells the engine that our new class is an object that can ‘exist’ in the world. it’s a ‘thing’ where as rendering function is not.
protected:
// Called when the game starts
virtual void BeginPlay() override;
there is a global function called BeginPlay() which is executed when the game starts. This virtual function allows statements to be ‘added’ onto the BeginPlay() function. It’s protected meaning it’s public but can not be manipulated.
Going over the cpp file.
UPositionReport::UPositionReport()
We’ve created a method (named the same as the class) that we use to initialize the class.
void UPositionReport::BeginPlay()
{
Super::BeginPlay();
// ...
}
Super::BeginPlay(); BeginPlay must be a method in the UActor class and has been inherited, so by calling Super:: we’re asking the program not to run UPositionReport()'s begind play but instead the parent class begin play. However UPositionReport has added it’s own code to the master. So when the game starts, it’s calling one function that all other actors have added to, rather than calling a separate BeginPlay() function for every single componenet.
So I believe it’s more for optimizations than anything else.
void UPositionReport::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
Finally we get the final TickComponent. Which basically is a constantly firing method that occurs in most game engines. Again it’s appending the actors code to the “super code” so it only needs to run 1 function every tick, rather than 100+ (numbers of actors in the scene).
Deltatime I believe defines the tickrate? CS:GO runs on 64 tick for example (64 ticks a.k.a checks per second) however custom servers run on 100 tick which improves the game in almost every way (responsiveness, hitboxes etc, because there’s more checking!)
ELevelTick TickType
ELevelTick is an Enum, we know this because of Unreal’s code practise. I assume there are several ways to define the tickrate. One being by time, but another type is by matching the tickrate to the frame rate, but that would be terrible for multiplayer.
FActorComponentTickFunction* ThisTickFunction
A pointer to a function… I’m assuming FActorComponentTickFunction() is the actual function that actually implents this kind of ‘ticking’ into the game.
edit: reading back on my post I think my details are WRONG but my general idea of what is happening is correct.