I noticed that if I make changes to the rotation constraints in the c++ code and then try and test those changes by playing the game, the constraints on the Details tab for the affected object look correct but the object is still rotating.
Please see the following video to better understand the issue: https://youtu.be/2mfLelTaOfY
Here is the header section for the affected variables:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Liftables")
bool bIsHoldingObject;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Liftables")
class AActor* HeldObjectRef;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Liftables")
class UStaticMeshComponent* HeldObjectStaticMesh;
Here is the code in the cpp:
void AFP_MainPlayer::PickUpObject()
{
if (!bIsHoldingObject)
{
if (TracedObject)
{
bIsHoldingObject = true;
HeldObjectRef = TracedObject;
HeldObjectRef->SetActorRotation(FRotator::ZeroRotator);
HeldObjectStaticMesh = Cast<UStaticMeshComponent>(HeldObjectRef->GetComponentByClass(UStaticMeshComponent::StaticClass()));
HeldObjectStaticMesh->SetEnableGravity(false);
HeldObjectStaticMesh->BodyInstance.bLockXRotation = true;
HeldObjectStaticMesh->BodyInstance.bLockYRotation = true;
HeldObjectStaticMesh->BodyInstance.bLockZRotation = true;
}
}
else
{
bIsHoldingObject = false;
HeldObjectStaticMesh->SetEnableGravity(true);
HeldObjectStaticMesh->BodyInstance.bLockXRotation = false;
HeldObjectStaticMesh->BodyInstance.bLockYRotation = false;
HeldObjectStaticMesh->BodyInstance.bLockZRotation = false;
HeldObjectRef = nullptr;
}
}