USceneComponent::RelativeRotation': cannot access private member declared in class 'USceneComponent

Following along Ben Tristens C++ Course for Unreal, and im receiving this error where as he is not Ive had the issue throughout the course usually because theirs something I have to include that he didn’t due to changes to the engine but im not sure how to get past this one. The error is being caused by this line

auto RawNewElevation = RelativeRotation.Pitch + ElevationChange;

I’m assuming there’s something I can change to allow access to the USceneComponents private stuff but I’m not sure where or how to go about it.

Any advice would be greatly appreciated thanks. :slight_smile:

From the error it seems that RelativeRotation was declared private and not public.

Where and how are RelativeRotation and ElevationChange variables declared?

Yeah its not but its a engine header file, there must be a way to get around it without rewriting engine files or is that normal.

TankBarrel.cpp(16): error C2248: ‘USceneComponent::RelativeRotation’: cannot access private member declared in class ‘USceneComponent’

1>H:\UE_4.25\Engine\Source\Runtime\Engine\Classes\Components/SceneComponent.h(158): note: see declaration of ‘USceneComponent::RelativeRotation’

void UTankBarrel::Elevate(float RelativeSpeed)
auto Time = GetWorld()->GetTimeSeconds();

// Move the barrel the right amount this frame

// Given a max elevation speed, and the frame time

auto ElevationChange = RelativeSpeed * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;

auto RawNewElevation = RelativeRotation.Pitch + ElevationChange;

SetRelativeRotation(FRotator(RawNewElevation, 0, 0));



 auto RawNewElevation = GetRelativeRotation().Pitch + ElevationChange;

It looks like in 4.25 all replicated properties in USceneComponent are now private, and must be accessed through the respective accessor functions.


Oh really okay thanks, What does that mean for me here how can I use it.

Just replace RelativeRotation with GetRelativeRotation().

That worked. Thanks for pointing it out. You are the best :slight_smile:

You sir saved my life with this. I’m new to C++ and could not figure out how to actually use the new methods. I was doing it way wrong not realizing that the class I was using was a child of the USceneComponent class meaning I could just call the method on the class I was using. I ended up trying to create an instance of that class to set this variable and the RelativeRotation but kept getting access violations.

You saved me a lot of headaches, thanks.