Reputation: 75
So I'm new to Unreal Engine 4 and thought the docs posted on their website would be a good place to start. However, I'm struggling with some things concerning the coding part (I have a pretty decent C++ knowledge). Here is the code extract I'm having some trouble with:
void AFloatingActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
FVector NewLocation = GetActorLocation();
float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
NewLocation.Z += DeltaHeight * 20.0f; //Scale our height by a factor of 20
RunningTime += DeltaTime;
SetActorLocation(NewLocation);
}
I do not get how this works. I pretty much get the statements and all but I don't get how it works. So tick basically is a function called each tick (frame) and any other statements added are to edit the logic of the actor each frame. How does this work? Shouldn't the first statement "Super::Tick ( DeltaTime );" cause an endless recursion as there is no base (stopping) case? Any help would be appreciated. Thank you so much
Upvotes: 3
Views: 7662
Reputation: 58929
There's no recursion here - it's calling Super::Tick
, not itself.
Super
is most likely a typedef of the base class, intended so that you can call its functions without having to remember its actual name in all situations.
So Super::Tick(DeltaTime);
calls the Tick
function in the base class (and passes it DeltaTime
as an argument). This is useful if you override a function, but still want the "normal" stuff to happen as well as the stuff you wrote in your override.
Upvotes: 3