Hi,
I’m having some trouble setting the relative location of a skeletal mesh component via code.
I’m trying the following but it does nothing:
Mesh->CastShadow = true;
Mesh->SetRelativeLocation(FVector(0.0f, 0.0f, -100.0f), false);
RootComponent = ArmMesh;
Some help would be appreciated very much.
Thanks!
My situation:
I have a weapon class extended from Actor, and I added a SkeletalMeshComponent to it. I want to set the Actor’s location to the Pawn’s eye location, and then apply a relative location transform to the SkeletalMeshComponent so the arms are in the right place when rotating the camera.
The only way I could achieve this was to add a dummy Root Component (e.g. Capsule), and set the SkeletalMeshComponent’s AttachParent to this dummy root component.
E.g. my Weapon class constructor looks like this:
APWNWeapon::APWNWeapon(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// Enable ticking
PrimaryActorTick.bCanEverTick = true;
// Find skel mesh models
static ConstructorHelpers::FObjectFinder<USkeletalMesh> armSkelMeshLeftOb(TEXT("SkeletalMesh'/Game/PWNGame/FPSArms/FPSArms_L.FPSArms_L'"));
if (armSkelMeshLeftOb.Object != NULL)
LeftArmMesh = armSkelMeshLeftOb.Object;
static ConstructorHelpers::FObjectFinder<USkeletalMesh> armSkelMeshRightOb(TEXT("SkeletalMesh'/Game/PWNGame/FPSArms/FPSArms_R.FPSArms_R'"));
if (armSkelMeshRightOb.Object != NULL)
RightArmMesh = armSkelMeshRightOb.Object;
//Root
RootCapsule = PCIP.CreateDefaultSubobject<UCapsuleComponent>(this, TEXT("CollisionCylinder"));
RootCapsule->InitCapsuleSize(30.0f, 80.0f);
RootCapsule->SetCollisionEnabled(ECollisionEnabled::NoCollision);
RootCapsule->SetCollisionResponseToAllChannels(ECR_Ignore);
RootCapsule->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
RootComponent = RootCapsule;
// Create Arm Mesh object
ArmMesh = PCIP.CreateDefaultSubobject<UPWNSkeletalMeshComponent>(this, TEXT("ArmMesh"));
ArmMesh->MeshComponentUpdateFlag = EMeshComponentUpdateFlag::OnlyTickPoseWhenRendered;
ArmMesh->bChartDistanceFactor = false;
ArmMesh->bReceivesDecals = true;
ArmMesh->CastShadow = true;
ArmMesh->SetCollisionObjectType(ECC_WorldDynamic);
ArmMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
ArmMesh->SetCollisionResponseToAllChannels(ECR_Ignore);
// Set the relative transform by taking other transforms into account
FTransform relTrans = ArmMesh->GetRelativeTransform();
relTrans.SetLocation(FVector(1.0f, 1.0f, -50.0f));
ArmMesh->SetRelativeTransform(relTrans);
// Set parent to the RootCapsuleComponent
ArmMesh->AttachParent = RootCapsule;
}
Why does it not work with a predefined Fvector?