Hello, I am just starting out with Unreal and with developing for VR and I am having some issues setting up the VR_Pawn in C++. One thing I wanted to do was create a component derived from UMotionControllerComponent for the hands so that I didn’t have to replicate functionality for the left and right hand.
The issue I am having is when I try to make a blueprints class based on the VR_Pawn that I have created. The component heirarchy that I expect is completely thrown off, for example, I would expect to see each HandComponent to have a static mesh and an arrow component, however the blueprint shows that one of the HandComponents is storing BOTH meshes and the other HandComponent is storing BOTH arrow components (or some other random combination of the components). Am I approaching this from the wrong angle? Is the issue that they have the same name? Thank you in advanced for your help! Here is the code:
Blueprints result
HandComponent.h
UCLASS()
class OVERSHOULDERS_API UHandComponent : public UMotionControllerComponent
{
GENERATED_BODY()
public:
//Set Default Values
UHandComponent();
UPROPERTY(VisibleAnywhere)
class AInteractActor* IsBusy;
UPROPERTY(VisibleAnywhere)
class AInteractActor* Nearby;
UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* Mesh;
UPROPERTY(VisibleAnywhere)
UArrowComponent* HoldLocation;
};
UHandComponent.cpp
UHandComponent::UHandComponent() {
IsBusy = NULL;
Nearby = NULL;
// Create Mesh for Hand
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
Mesh->AttachTo(this);
Mesh->RegisterComponent();
// Create Arrow Component as attach location for objects
HoldLocation = CreateDefaultSubobject<UArrowComponent>(TEXT("Hold Location"));
HoldLocation->AttachTo(this);
HoldLocation->RegisterComponent();
}
VR_Pawn.h
UCLASS()
class OVERSHOULDERS_API AVR_Pawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AVR_Pawn();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
UPROPERTY(VisibleAnywhere)
USceneComponent* DefaultRoot;
UPROPERTY(VisibleAnywhere)
UCapsuleComponent* Body;
UPROPERTY(VisibleAnywhere)
USceneComponent* Container;
UPROPERTY(VisibleAnywhere)
UCameraComponent* HMD;
UPROPERTY(VisibleAnywhere)
class UHandComponent* Left;
UPROPERTY(VisibleAnywhere)
class UHandComponent* Right;
UPROPERTY(VisibleAnywhere)
class USteamVRChaperoneComponent* SteamVR;
};
VR_Pawn.cpp constructor
// Sets default values
AVR_Pawn::AVR_Pawn()
{
// 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;
BaseEyeHeight = 0.0f;
// Create Default Root Object
DefaultRoot = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
//DefaultRoot->SetRelativeLocation(FVector(0, 0, 0));
// Create the Body of the player in the space
Body = CreateDefaultSubobject<UCapsuleComponent>(TEXT("BODY"));
//Body->SetRelativeLocation(FVector(0, 0, 0));
Body->SetCapsuleHalfHeight(96);
Body->SetCapsuleRadius(16);
// Create a Scene Object Holder for Camera and Controllers
Container = CreateDefaultSubobject<USceneComponent>(TEXT("Container"));
//Container->SetRelativeLocation(FVector(0, 0, -110));
// Create the Camera and subsequent HMD
HMD = CreateDefaultSubobject<UCameraComponent>(TEXT("HMD"));
HMD->SetupAttachment(Container);
// Create the Hand Controllers
Left = CreateDefaultSubobject<UHandComponent>(TEXT("Left"));
Left->SetupAttachment(Container);
Left->RegisterComponent();
Left->Hand = EControllerHand::Left;
Right = CreateDefaultSubobject<UHandComponent>(TEXT("Right"));
Right->SetupAttachment(Container);
Right->RegisterComponent();
Right->Hand = EControllerHand::Right;
// Create SteamVR Chaperone
SteamVR = CreateDefaultSubobject<USteamVRChaperoneComponent>(TEXT("SteamVRChaperoneComponent"));
AutoPossessPlayer = EAutoReceiveInput::Player0;
}