Detaching actor snaps back to original location

When my Character overlaps an item located in position A, i attach the item to the character skeletonMesh like this :

SomeItem->AttachRootComponentTo(GetMesh(), SocketName, EAttachLocation::SnapToTarget);

So far so good.

However when i walk around and detach that same item, it detaches but also immediately snaps back to position A.

I detach it like this :


I just want the item to fall off.
I’ve been struggling with this issue for sometime now.

Any help would be really appreciated.

Have you tried something like:

FVector SomeItemWorldLocation = SomeItem->GetActorLocation();
SomeItem->SetWorldLocation( SomeItemWorldLocation );

yes I have. I also tried to give it the character’s socket location. Doesn’t help.

I tracked the position of the item and I noticed that when the snapping/detaching occurs, the item’s location vector values don’t change, but the item still snaps and changes position.

That’s odd. Snapping to target should set relative location, rotation and scale to default values.

Could it be that when detached, the item is colliding with the character, and the engine resolves the collision by putting the item in the last known valid location ?

it may be far fetched but I’m grasping at straws here lol

Edit :
When i set simulate physics to false on the item, it stays where it should be when detaching.

After some testing, I think the problem comes from switching SetSimulatePhysics from false to true.
It’s like the engine doesn’t take into account all the movement the object does when it’s not simulating physics. And when physics are switched on, it just goes back the last know state when physics were on.

I still can’t figure out how to fix that.

You may need to work with the FBodyInstance that every component has (or is it actor?) It’s GetBody() i think or just BodyInstance or something on the actor.

Check the API.

The pattern that causes the problem is this :

-Switch physics off on an object

-Attach object to a parent

-move parent

-detach object and set its physics to true

-detached object’s location will be set to its last location before settings physics to false in the next frame.

I don’t have an explanation, but for those facing this issue, I just work around it by waiting for one frame after detaching the object and setting its position manually.

I’m having a similar issue in 4.12 , it only happens when attaching a networked actor to another networked actor on the client, when I detach and set the physics back on to simulate it warps to the origin.

Any ideas on correct way to fix this, is this a bug with unreal?

The Correct solution for me to this problem is calling “RecreatePhysicsState()” on the component that is simulating physics. You should call this in the same frame after detachment from the parent.

This seems to fix the body snapping back problem