Nested Components ?

Hi guys, please help me understand nested components.

I want to create a character (VRCharacter) with two components created in C++ for left and right hand, of the same type, let it be VRMotionControllerComponent.

In this component I create a mesh and attach a spline (or several splines) to it.

After that I create a blueprint inherited from the character class, I see that in the tree all components are added as intended.

But when I move the mesh in the viewport, the spline stays in place, even though it is a child of the mesh.


What are the mobility setting for the splines? Maybe they are not set to movable?

Its set to movable :frowning:

It should move with the mesh no problem. I made a quick scene with an attached spline and all works as expected


Maybe check up the chain if the parent is ok?

1 Like

Thansk for u time bro, but you have added both components to the actor class. My situation is a little different. I have a VRMotionController component in the actor, and the meshes and spline are already in it. Please look at the screenshots in the first post carefully.

Character -> VRMotionController Component -> Mesh Component
-------------------------------------------> Spline Component

I’ll recreate it later in the day, I’ll have to wait for my quest to charge as it’s at 0% atm.

Thanks man! Actually there is no need to use MotionControllerComponent, similar situation if you inherit a class from UChildActorComponent or UActorComponent, no difference.

Made a child actor attached to character mesh.
Child actor is a skeletal mesh with attached spline.
Added in motion and spline follows the mesh in the child actor from within a character no problem.

All updates as expected

Thanks for helping me figure it out and spending your time! The thing is, the problem only occurs when you do everything in C++. I have recorded a video where you can see the problem.

It must be motion controller related.
My project was also pure c++ and nothing like that happened during motion.
The hand mesh looks almost like it’s getting a double transform while in motion.
The motion controller itself also has no transform node if you haven’t noticed. Only scale is accessible.

I’ll need to do a test directly with the motion controller.

Also I noticed you are using live coding. Maybe it is interfering with the correct compile. Lot’s of things break with it as many elements do not support proper hot reloading. Try disabling live coding, closing the project and doing a proper recompile.

If MotionController does not have a transformation node, how can I make it work the way I want?

For example, inherit my VRMotionController class from USceneComponent and put the MotionController class in it?

Ok looking at the example in the engine XRCreativeAvatar.cpp it has the character and it’s controllers and meshes all created inside of the character itself.

I made a similar setup


ATestCharacter::ATestCharacter()
{
	PrimaryActorTick.bCanEverTick = true;

	L_MotionController = CreateDefaultSubobject<UTestMotionControllerComponent>(TEXT("L MotionController"));	
	L_MotionController->bTickInEditor = true;
	L_MotionController->MotionSource = "Left";

	MeshLeft = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MeshL"));
	MeshLeft->SetupAttachment(L_MotionController);
	SplineLeft = CreateDefaultSubobject<USplineComponent>(TEXT("SplineL"));
	SplineLeft->SetupAttachment(MeshLeft);


	R_MotionController = CreateDefaultSubobject<UTestMotionControllerComponent>(TEXT("R MotionController"));
	R_MotionController->bTickInEditor = true;
	R_MotionController->MotionSource = "Right";

	MeshRight = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MeshR"));
	MeshRight->SetupAttachment(R_MotionController);
	SplineRight = CreateDefaultSubobject<USplineComponent>(TEXT("SplineR"));
	SplineRight->SetupAttachment(MeshRight);
}

The splines and hands follow the controllers in this config.
I’m guessing the SetupAttachment(this) inside of the motioncontroller was the fail point. Maybe it’s not ready during the motion controllers CDO.

Maybe setting an attachment another point of init it might work in InitializeComponent?
Anyway the upper code works ok though it is a little less flexible.

Edit:
after scouring some of the ue source code it seems you can override the OnRegister function and setup the attachments there, but it has it’s pitfalls (you need some extra safeguards) and haven’t tested it out yet in packed projects.

I was able to do what I wanted with the ChildActorComponent. But one problem remains, the motion controllers are now fixed at one point and do not move with the joysticks, any ideas?

Did you set the motion source for the Motion controllers?

example:

R_MotionController->MotionSource = "Right";

You can find them in OpenXRSourceNames of OpenXRInput.cpp

namespace OpenXRSourceNames
{
	static const FName Head("Head");
	static const FName AnyHand("AnyHand");
	static const FName Left("Left");
	static const FName Right("Right");
	static const FName LeftGrip("LeftGrip");
	static const FName RightGrip("RightGrip");
	static const FName LeftAim("LeftAim");
	static const FName RightAim("RightAim");
	static const FName LeftPalm("LeftPalm");
	static const FName RightPalm("RightPalm");
}

For both hands, of course. Triggers work, movements don’t, I think this is due to the way the transformation node works when using ChildActorComponent. Apparently it is overwritten with other values somewhere.