Hello,
Sorry if this is super simple, but I’m pretty new to UE4 and trying to stumble my way through things. I’ve been working with VR and parenting objects to the players hand so they can grab and release certain objects in the world. I’m basically trying to mimic Unreal’s BP_PickupCube functionality, but via C++ instead of blue prints.
What seems to be happening is if the object I’m trying to pick up has ever had physics simulated on it, it no longer allows me to “Pick it up” It appears the parenting is still working, but when I move my hand around the object stays on the ground in the same spot.
I noticed that I wasn’t the only one to encounter this issue, but I found a resolution in the BP section of the forum (Here: Includes video of problem), and I don’t fully understand how the solution is different from what I’m doing.
So when I reach out into the world and overlap an object if I push the grab button I call this function on my “MovableObject”:
void UMovableObject::Grab(USceneComponent* hand)
{
GetOwner()->GetComponents(mPhysicsComponents);
if (mPhysicsComponents.Num() != 0)
{
for (UStaticMeshComponent* Component : mPhysicsComponents)
{
Component->SetSimulatePhysics(false);
}
}
GetOwner()->AttachToComponent(hand,FAttachmentTransformRules::KeepWorldTransform, NAME_None);
}
When I release the object I’m calling this function:
void UMovableObject::Drop()
{
// Release all buttons.
for (int i = 0; i < 3; i++)
{
mButtonPressed* = false;
}
// Re-enable all the physics we turned off when we grabbed it.
if (mPhysicsComponents.Num() != 0)
{
for (UStaticMeshComponent* Component : mPhysicsComponents)
{
Component->SetSimulatePhysics(true);
}
}
GetOwner()->DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
}
If I start the game with SimulatePhysics unchecked then when I grab it the first time everything works as expected. However when I release the object (and enable physics) I can never pick it up again. Also if I start the game with SimulatePhysics checked then I can never move the object.