Hi!
I’m using Unreal Engine 5.4.4.
In the same project I have a Blueprint with Pawn as parent class, and another blueprint with a C++ Pawn parent class. The first one works perfectly, I see the movement of the controllers in the game and the Trigger button fires an event. But the second one, the C++ pawn, doesn’t do anything.
This is the header and code of the C++ class:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "SNVRPawn.generated.h"
class UCameraComponent;
class UWidgetInteractionComponent;
class UMotionControllerComponent;
class UXRDeviceVisualizationComponent;
class USNMannequinsXR;
UCLASS()
class MYGAME_API ASNVRPawn : public APawn
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<USceneComponent> VROrigin;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UMotionControllerComponent> MotionControllerLeftGrip;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UMotionControllerComponent> MotionControllerRightGrip;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UMotionControllerComponent> MotionControllerLeftAim;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UMotionControllerComponent> MotionControllerRightAim;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UXRDeviceVisualizationComponent> XRDeviceVisualizationLeft;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UXRDeviceVisualizationComponent> XRDeviceVisualizationRight;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<USNMannequinsXR> HandRight;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<USNMannequinsXR> HandLeft;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UWidgetInteractionComponent> WidgetInteractionLeft;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UWidgetInteractionComponent> WidgetInteractionRight;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UCameraComponent> Camera;
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
TObjectPtr<UStaticMeshComponent> HeadMountedDisplayMesh;
// Sets default values for this pawn's properties
ASNVRPawn();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
The code:
#include "SNVRPawn.h"
#include "MotionControllerComponent.h"
#include "Components/WidgetInteractionComponent.h"
#include "XRDeviceVisualizationComponent.h"
#include "SNMannequinsXR.h"
#include "Camera/CameraComponent.h"
// Sets default values
ASNVRPawn::ASNVRPawn()
{
// 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;
VROrigin = CreateDefaultSubobject<USceneComponent>(TEXT("VR Origin"));
SetRootComponent(VROrigin);
MotionControllerLeftGrip = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Motion Controller Left Grip"));
MotionControllerLeftGrip->MotionSource = FName(TEXT("LeftGrip"));
MotionControllerRightGrip = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Motion Controller Right Grip"));
MotionControllerRightGrip->MotionSource = FName(TEXT("RightGrip"));
XRDeviceVisualizationLeft = CreateDefaultSubobject<UXRDeviceVisualizationComponent>(TEXT("XRDevice Visualization Left"));
XRDeviceVisualizationRight = CreateDefaultSubobject<UXRDeviceVisualizationComponent>(TEXT("XRDevice Visualization Right"));
MotionControllerLeftAim = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Motion Controller Left Aim"));
MotionControllerLeftAim->MotionSource = FName(TEXT("LeftAim"));
MotionControllerRightAim = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Motion Controller Right Aim"));
MotionControllerRightAim->MotionSource = FName(TEXT("RightAim"));
HandLeft = CreateDefaultSubobject<USNMannequinsXR>(TEXT("Hand Left"));
HandLeft->bMirror = true;
HandRight = CreateDefaultSubobject<USNMannequinsXR>(TEXT("Hand Right"));
WidgetInteractionLeft = CreateDefaultSubobject<UWidgetInteractionComponent>(TEXT("Widget Interaction Left"));
WidgetInteractionLeft->PointerIndex = 0;
WidgetInteractionLeft->TraceChannel = ECC_GameTraceChannel1;
WidgetInteractionRight = CreateDefaultSubobject<UWidgetInteractionComponent>(TEXT("Widget Interaction Right"));
WidgetInteractionRight->PointerIndex = 1;
WidgetInteractionRight->TraceChannel = ECC_GameTraceChannel1;
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
HeadMountedDisplayMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Head Mounted Display Mesh"));
HeadMountedDisplayMesh->SetCollisionProfileName(TEXT("NoCollision"));
HeadMountedDisplayMesh->SetOwnerNoSee(true);
MotionControllerLeftGrip->SetupAttachment(RootComponent);
XRDeviceVisualizationLeft->SetupAttachment(MotionControllerLeftGrip);
HandLeft->SetupAttachment(XRDeviceVisualizationLeft);
MotionControllerRightGrip->SetupAttachment(RootComponent);
XRDeviceVisualizationRight->SetupAttachment(MotionControllerRightGrip);
HandRight->SetupAttachment(XRDeviceVisualizationRight);
Camera->SetupAttachment(RootComponent);
HeadMountedDisplayMesh->SetupAttachment(Camera);
MotionControllerLeftAim->SetupAttachment(RootComponent);
WidgetInteractionLeft->SetupAttachment(MotionControllerLeftAim);
MotionControllerRightAim->SetupAttachment(RootComponent);
WidgetInteractionRight->SetupAttachment(MotionControllerRightAim);
}
// Called when the game starts or when spawned
void ASNVRPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ASNVRPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ASNVRPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
In the MyGame.Build.cs I use these modules:
PublicDependencyModuleNames.AddRange(new string[]
{
"Core",
"CoreUObject",
"Engine",
"InputCore",
"EnhancedInput",
"XRBase",
"HeadMountedDisplay",
"UMG"
});
Everything compile fine.
The Blueprint class which parent is this C++ class has these components:
And the blueprint class that works has these components:
Maybe I have forgotten to add something in C++.
Any idea about why the c++ pawn doesn’t work?
Thanks!