Download

Component transformation/rotation with quaternion class issue

Trying to modify a solution Rama posted a while backing that transforms an AActor to fix rotation gimbal issues, and change it to work for a sub-component class.
Play-in-editor sends errors that ‘Mobility’ is not enable for RootComponent, stopping it in place, and the Mesh component spawns far below the origin, not attaching to the root.
The code is in a c++ class extended from Pawn, parenting a blueprint class.
Any help greatly appreciated.

.cpp



 RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
 RootComponent->SetMobility(EComponentMobility::Movable);
 
 Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh"));
 Mesh->AttachTo(RootComponent);
 Mesh->SetSimulatePhysics(true);

.h


// Original code by Rama
 FORCEINLINE void AddToRot(USkeletalMeshComponent* Mesh, const FRotator& AddRot) const
 {
 if (!Mesh) return;
 
 FTransform TheTransform = Mesh->GetRelativeTransform();
 TheTransform.ConcatenateRotation(AddRot.Quaternion());
 TheTransform.NormalizeRotation();
 Mesh->SetRelativeTransform(TheTransform);
 }
 
 UPROPERTY(EditAnywhere)
 USkeletalMeshComponent* Mesh;

Had difficulties choosing the right “UClass”, USkeletalMeshComponent seems to be almost the only valid choice that allows ‘*Transform’ functions to be called.

**Blueprint setup
**
Component hierarchy:

82563-bpcomponents.png

Input adds to the rotation of the pawn’s SpringArm camera, which sets the ‘Mesh’ component’s rotation:

cb04e55101812ec9afbe732d32d76fc013c00254.png