Physics Constraint Component works in blueprint, but not C++

Hello!

I’m trying to make physics-driven VR hands, and for that purpose I am spawning hand actors and binding them with a physics constraint to a child object of a MotionControllerComponent.

When I create this in Blueprint only, it works exactly as intended. But when I try to recreate it with C++, the constraint seems to fail.

image

The above is the Blueprint code. When I run this it works, and the physics constraint looks like this:

image

Here I’ve attempted to recreate this in C++

But when I run this, the hands do not attach to the motion controllers, they just fly off. The physics constraints look like this:

image

As far as I can tell, the component setups are identical and the code should be doing the same thing, and the constraints seem to have the right data with C++. If anything, the data is more correct as the BP version doesn’t have actor pointers, just component names.

But clearly it doesn’t work, and I just don’t understand why. The biggest difference I can find between the two is that the BP “Setup Constrain Components” take component references rather than just FNames, but I figure having pointers to the correct actors should be enough of a reference for the C++ version to constrain the correct components.

I’d love any input or suggestions about what could be going wrong here.

Well, nevermind, I figured it out myself.

First off, when I tried to find the SetConstrainCompoents in C++, the autocomplete didn’t work at first, so I thought it didn’t exist. Turns out it does.

I checked the source code and noticed it does some initialization and uses some private variables that I didn’t do when I tried to do it in my own code:

image

So, I changed my code to this, and now everything works perfectly.

1 Like

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