(Unreal Engine 5.7.1)
Motion Controller Component has blueprint useable “Get” methods inaccessible (protected) in C++
UMotionControllerComponent* pMotionController;
FVector linearVelocity;
FRotator angularVelocity;
pMotionController->GetLinearVelocity(linearVelocity);
pMotionController->GetAngularVelocity(angularVelocity);
‘UMotionControllerComponent::GetLinearVelocity’: cannot access protected member declared in class ‘UMotionControllerComponent’
‘UMotionControllerComponent::GetAngularVelocity’: cannot access protected member declared in class ‘UMotionControllerComponent’
I can think of no reason these functions, which we can use freely in blueprints, can’t be used as
public methods in C++.
There are a bunch of random functions that aren’t public for no discernable reason, or classes like AInfo which are explicitly disabled either in blueprints or in C++, so forums are full of obtuse solutions where we have to create redundant “Ex” or “My” classes to inherit an existing, otherwise perfectly fine class, to expose a single function or enable the class in blueprints, e.g.
class UMotionControllerComponentEx : public UMotionControllerComponent {
public:
// No need to make BlueprintCallable since blueprints can just call GetLinearVelocity or GetRadialVelocity()
void GetVelocities(FVector& linearVelocity, FRotator& angularVelocity)
{
// Now we can call protected methods.
GetLinearVelocity(linearVelocity);
GetAngularVelocity(angularVelocity);
}
};
// ... or
UCLASS(Blueprintable) class AInfoActorEx : public AInfo {};