Hello Answerhub, I’ve been attempting to socket an actor which has physics enabled on by disabling the physics then attaching then disabling the physics on detachment.
From all material that I’ve found online it seems that this should work but despite that, if the physics is not enabled at the start and is enabled at drop, you can pick it up, put it down and then never pick it up again.
If you activate physics from the start, the item will never socket right but will still run through the motions, physics will show as disabled in the details panel and it will show as being attached to the character.
I’ve tried waiting a frame aswell as going through a wide variety of different API functionality to see if I can get this to work with no luck.
Here is my current code for both my pickup and drop:
void ACP_Character::BeginUseAction()
{
if(currentLootBag && !heldLootBag)
{
if(!hasBag)
{
//Preventing this being called again
hasBag = true;
heldLootBag = currentLootBag;
//Set the collision and physics
TArray<USceneComponent*> components;
heldLootBag->GetComponents(components);
UStaticMeshComponent* meshComponent = Cast<UStaticMeshComponent>(components[1]);
//TODO - Fix issues with being unable to pick up the item once physics are enabled
heldLootBag->SetActorEnableCollision(false);
meshComponent->SetSimulatePhysics(false);
//meshComponent->PutAllRigidBodiesToSleep();
//meshComponent->RecreatePhysicsState();
//Attach the item to our socket
const FAttachmentTransformRules attachmentRules(EAttachmentRule::SnapToTarget, true);
heldLootBag->AttachToComponent(GetMesh(), attachmentRules, FName("BagBone"));
//Return to ensure the loot action is not followed
return;
}
}
}
void ACP_Character::ThrowBagAction()
{
if(hasBag)
{
//Detach the item from the socket
const FDetachmentTransformRules detachRules(EDetachmentRule::KeepWorld, false);
heldLootBag->DetachFromActor(detachRules);
//Turn the physics and collision back on
TArray<USceneComponent*> components;
heldLootBag->GetComponents(components);
UStaticMeshComponent* meshComponent = Cast<UStaticMeshComponent>(components[1]);
//TODO - Fix issues with being unable to pick up the item once physics are enabled
heldLootBag->SetActorEnableCollision(true);
meshComponent->SetSimulatePhysics(true);
//meshComponent->WakeAllRigidBodies();
//meshComponent->RecreatePhysicsState();
//Rest values to allow future bags to be picked up
heldLootBag = nullptr;
hasBag = false;
}
}
If anyone at all could help with a fix or advise I would eternally within your debt, this issue has persisted for a while and I’ve attempted to find an answser on Reddit and the official forums with no results.
Thank you.