in C++
in my arm component .h file :
protected:
UPROPERTY(SkipSerialization)
USkeletalMeshComponent* ArmSkeletalMesh;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FTransform ArmMeshRelativeTransform;
in my arm component .cpp file :
#define MAKE_SUBCOMPONENT_NAME(ParentName, SubObjectName) FName(*FString::Printf(TEXT("%s_%s"), *ParentName, TEXT(SubObjectName)))
UArmComponent::UArmComponent(const FObjectInitializer& ObjectInitializer)
{
// arm 1st person mesh
FString ArmName = GetName();
ArmSkeletalMesh = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, MAKE_SUBCOMPONENT_NAME(ArmName, "ArmSkeletalMesh"), true);
ArmSkeletalMesh->SetupAttachment(this);
ArmSkeletalMesh->bEditableWhenInherited = true;
// parameters that used to be set in the blueprint
// but they have no reason to be changed
ArmSkeletalMesh->bOnlyOwnerSee = true;
ArmSkeletalMesh->CastShadow = false;
ArmSkeletalMesh->bCastDynamicShadow = false;
ArmSkeletalMesh->bAffectDynamicIndirectLighting = false;
ArmSkeletalMesh->bAffectDistanceFieldLighting = false;
ArmSkeletalMesh->bCastStaticShadow = false;
}
void UArmComponent::BeginPlay()
{
Super::BeginPlay();
// apply the transform that was set in the blueprint
ArmSkeletalMesh->SetRelativeTransform(ArmMeshRelativeTransform);
}
I hope this helps you