SetupAttachment not attaching the properties propertly

Hi!

I’m developing with Unreal 5.3.2.

I have a Pawn class with this constructor:

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"));
	MotionControllerRightGrip = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Motion Controller Right Grip"));

	XRDeviceVisualizationLeft = CreateDefaultSubobject<UXRDeviceVisualizationComponent>(TEXT("XRDevice Visualization Left"));
	XRDeviceVisualizationRight = CreateDefaultSubobject<UXRDeviceVisualizationComponent>(TEXT("XRDevice Visualization Right"));

	MotionControllerLeftAim = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Motion Controller Left Aim"));
	MotionControllerRightAim = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Motion Controller Right Aim"));

	HandLeft = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Hand Left"));
	HandRight = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Hand Right"));

	WidgetInteractionLeft = CreateDefaultSubobject<UWidgetInteractionComponent>(TEXT("Widget Interaction Left"));
	WidgetInteractionRight = CreateDefaultSubobject<UWidgetInteractionComponent>(TEXT("Widget Interaction Right"));

	Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
	HeadMountedDisplayMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Head Mounted Display Mesh"));

	MotionControllerLeftGrip->SetupAttachment(XRDeviceVisualizationLeft);
	MotionControllerLeftGrip->SetupAttachment(HandLeft);
	VROrigin->SetupAttachment(MotionControllerLeftGrip);

	MotionControllerRightGrip->SetupAttachment(XRDeviceVisualizationRight);
	MotionControllerRightGrip->SetupAttachment(HandRight);
	VROrigin->SetupAttachment(MotionControllerRightGrip);

	Camera->SetupAttachment(HeadMountedDisplayMesh);
	VROrigin->SetupAttachment(Camera);

	MotionControllerLeftAim->SetupAttachment(WidgetInteractionLeft);
	VROrigin->SetupAttachment(MotionControllerLeftAim);

	MotionControllerRightAim->SetupAttachment(WidgetInteractionRight);
	VROrigin->SetupAttachment(MotionControllerRightAim);	
}

I have declared the properties in this way:



public:

	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<USceneComponent> VROrigin;

	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UMotionControllerComponent> MotionControllerLeftGrip;
	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UMotionControllerComponent> MotionControllerRightGrip;

	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UMotionControllerComponent> MotionControllerLeftAim;
	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UMotionControllerComponent> MotionControllerRightAim;

	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UXRDeviceVisualizationComponent> XRDeviceVisualizationLeft;
	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UXRDeviceVisualizationComponent> XRDeviceVisualizationRight;

	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<USkeletalMeshComponent> HandRight;
	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<USkeletalMeshComponent> HandLeft;

	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UWidgetInteractionComponent> WidgetInteractionLeft;
	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UWidgetInteractionComponent> WidgetInteractionRight;

	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UCameraComponent> Camera;
	UPROPERTY(BlueprintReadOnly)
	TObjectPtr<UStaticMeshComponent> HeadMountedDisplayMesh;

In the editor I have created a blueprint which inherits from the C++. When I open the bueprint class, I get this mess:

All the properties are unordered and VROrigin doesn’t appear as the root component.

What’s happening?

Thanks!

I’ve found the solution:

	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);

Hi!

I have a question that kind of is relevant for this issue as I am currently trying to understand the coherence between Motion Controller and XRDeviceVisualization, and when I searched for “XRDeviceVisualization” this was the only post present.

The VR-character I am working on has previously used Motion Controller to display the device model but as of quite recent times this usage stopped working and it currently says that it has been deprecated. It is asking me to use the XRDeviceVisualizationComponent instead for rendering and it kind of works if I set the controller as the static mesh. But with the previous system it could identify which VR-headset was being used and the visual controller would change thereafter.

This might come out as quite confusing but the reason behind it is that I am confused myself :slightly_smiling_face:

Simply put, do you have any experience with XRDeviceVisualization and how/if you can use that to switch the controller depending on what VR-headset is being used.

Thanks in advance!

Hi!

Sorry, but I have no idea. I’ve just started to develop VR games. You can ask your question in the OpenXR forum.

Bye!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.