Why do we need this last bit of code?

Hi again. Sorry if this is a dumb question ( mine always are )

But why do we need this last bit of code here? ( GetOwner()->GetActorRotation(); )
I don’t understand its use.

FRotator DoorRotation = GetOwner()->GetActorRotation();
DoorRotation.Yaw = CurrentYaw; 

Vs

FRotator DoorRotation;
DoorRotation.Yaw = CurrentYaw; 

Both seam to work when testing. But I am unsure as to why we apply the rotation of our actor to the door rotation only to define it with CurrentYaw a moment later. Thanks!

1 Like

The first one initializes all values of DoorRotation. The second one only initializes the Yaw. Usually, you should strive to initializes all values of a variable.

2 Likes

As you can see in the above screenshot I tried the thing you said and displayed it and it’s easily visible that we need to manually initialize all the values the first time to the FRotator OpenDoor1 if we want to keep updating it.

1 Like

FRotator DoorRotation; <— This is a declared, but not initialized, FRotator named DoorRotation. FRotator is a struct, which contains lots of different elements that can be accessed, three of which are Yaw, Pitch, and Roll - the rotation coordinates, persay. Still, if we don’t assign it a value by initializing it, then here:
DoorRotation.Yaw = CurrentYaw; We’re still accessing DoorRotation’s Yaw - but if we didn’t set DoorRotation’s value, then this will be the default value of 0.

Hope this helps,
Cheers
Tele

P.S. There are no stupid questions, I understood nothing 6 months ago. Asking questions is a sign of intelligence, not stupidity.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms