Hello, I’m not sure if I’m understanding how a local variable work, I’m doing the “Unreal Engine 5 C++ Developer: Learn C++ & Make Video Games”.
I’m in section 3 between video 50 and 53.
Well in the video 50 we’ll see the local variables and the code in that is:
// Called every frame
void AMovingPlatform::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector LocalVector = MyVector;
LocalVector.Z = LocalVector.Z + 100;
MyVector.Y = MyVector.Y + 1;
SetActorLocation(LocalVector);
This code only affect in the SetActorLocation and I understand after execution the LocalVector It gets reset every single time the function it’s called.
After that in Video 53 we end with the code:
// Called every frame
void AMovingPlatform::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// Move platform forward
// Get Current location
FVector CurrentLocation = GetActorLocation();
// Add vector to that location
CurrentLocation = CurrentLocation + PlatformVelocity * DeltaTime;
// Set the location
SetActorLocation(CurrentLocation);
// Send platform back if gone too far
// Check how far we've moved
// Reverse direction of motion if gone too far
}
In that code we will see that the vector gets the actor location and I understend the FVector CurrentLocation It gets reset every single time the function it’s called and in the new tick they get another time the values from actor location and the platform can move.
Sorry for my bad english.
Thank you.