Then, in the native base class constructor of my pawn, I create the components I need using CreateDefaultSubobject:
AVRArenaPawn_Base::AVRArenaPawn_Base()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
Root = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
RootComponent = Root;
PlayerCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("VRPlayerCamera"));
PlayerCamera->SetupAttachment(RootComponent);
Chaperone = CreateDefaultSubobject<USteamVRChaperoneComponent>(TEXT("Chaperone"));
AddOwnedComponent(Chaperone);
UVRArenaGlobalData* GlobalData = UVRArenaGlobalDataAccessLibrary::GetVRArenaGlobalData();
if (GlobalData)
{
TSubclassOf<UHandControllerComponent_Base> HandControllerComponentClass = GlobalData->HandControllerComponent_BPC;
if (HandControllerComponentClass)
{
UE_LOG(VRArenaGeneral, Log, TEXT("Generating hand components"));
//Hand_Left = Cast<UHandControllerComponent_Base>(CreateDefaultSubobject<HandControllerComponentClass>(TEXT("Hand_Left")));
//<HandControllerComponentClass>(TEXT("Hand_Left"));
Hand_Left = (UHandControllerComponent_Base*)CreateDefaultSubobject(TEXT("Hand_Left"), UHandControllerComponent_Base::StaticClass(), HandControllerComponentClass, false, false, false);
if (IsValid(Hand_Left))
{
Hand_Left->SetupAttachment(RootComponent);
Hand_Left->Hand = EControllerHand::Left;
}
else
{
UE_LOG(VRArenaGeneral, Error, TEXT("Left hand component creation failed"));
}
Hand_Right = (UHandControllerComponent_Base*)CreateDefaultSubobject(TEXT("Hand_Right"), UHandControllerComponent_Base::StaticClass(), HandControllerComponentClass, false, false, false);
if (IsValid(Hand_Right))
{
Hand_Right->SetupAttachment(RootComponent);
Hand_Right->Hand = EControllerHand::Right;
}
}
}
}