Download

How do I create multiple physics handles?

I have a character and I’m trying to make it so that one could pick up an object with each hand. I have a physics handler right now that works fine but I can only grab one item at a time, if I hit R(right hand grab button) the object is oriented relative to the right hand, and if I hit L(left hand grab button) the object is oriented relative to the left hand. Im guessing I need to use two different physics handlers but Im confused about how to create them in c++. Here is how I create my current one.

PhysicsHandle=GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();

Any help is greatly appreciated!

Thanks!

Well, that code isn’t actually creating a PhysicsHandle, as far as I can tell, but simply looking for an existing one on the actor.

To create a PhysicsHandle, you want something like this:



UPhysicsHandleComponent* NewPhysHandle = NewObject<NewPhysHandle>();


Sorry! Youre right, I wanted to find and correctly store two existing physics handles that I had attached as components to my game character. I managed to find the solution, by creating an array of actor components and trying to cast them one by one as UPHysicsHandleComponent. If the variable existed, I stored them accordingly. Thank you for your help!

I’m having trouble doing this myself, did you make an array with FindComponentByClass<UPhysicsHandleComponent> ?

Initially yes, I created an array of components and attempted to cast them as physics handles. But I then stored them within “UPhysicsHandle” objects that I named PhysicsHandleLeft and PhysicsHandleRight. I knew which one would come first because I created the left one before the right one in the pawn blueprint in UE, and it looks like thats the order that the function detects them in. Hopefully this helped!