# A problem with a C++ VR Pawn

**URL:** <https://forums.unrealengine.com/t/a-problem-with-a-c-vr-pawn/2252018>\
**Category:** XR Development\
**Tags:** unreal-engine, question\
**Created:** [December 31, 2024, 11:18am UTC](https://forums.unrealengine.com/t/a-problem-with-a-c-vr-pawn/2252018 "2024-12-31T11:18:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ViaCognita](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/viacognita/32/906601_2.png) [@ViaCognita](https://forums.unrealengine.com/u/ViaCognita)\
**Post date:** [December 31, 2024, 11:18am UTC](https://forums.unrealengine.com/t/a-problem-with-a-c-vr-pawn/2252018/1 "2024-12-31T11:18:02Z")

</div>

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:

```cpp
#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:

```cpp
#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:

```cs
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:

 ![imagen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/e/8/0e804c31caa24934fbd988bc0fec240d8d9c3391.png)

And the blueprint class that works has these components:

 ![imagen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/2/8/52800c823e6f9a076a65d58762fd3feb53d5c6ed.png)

Maybe I have forgotten to add something in C++.

Any idea about why the c++ pawn doesn’t work?

Thanks!
