OnComponentHit not getting called again after DetatchFromActor

Hi everyone!

I have a Pawn, called Pawn in this case, and I am attaching devices that I am calling gadgets to the Pawn. You can move around with the Pawn and do certain gadget actions. The Gadget Actors are more complex than a normal component would allow so I am using the AttachToActor function below to attach them to the Pawn with a weld.

GadgetActor->AttachToActor (Pawn, FAttachmentTransformRules(EAttachmentRule::KeepRelative, true));

The above code works fine and I am able to activate my gadgets as expected, move around with the Pawn and everything works great. The really weird behavior comes from the few gadgets that I have that can grab other world objects, in the case I talk about below I am only trying to grab basic shapes that have physics enabled at start.

Problem

Grabbing an object and releasing it works … for a single time. After I call Detach From Actor in the second screenshot below, OnComponentHit will never be called again when colliding with that specific actor.

For Example:

  • Actor A collides with Sticky Gadget
  • Actor A attached to the Sticky Gadget
  • Actor A detached from the Sticky Gadget
  • Actor A collides with Sticky Gadget again but OnComponentHit is not called
  • Actor B collides with Sticky Gadget and calls OnComponentHit

Stick to Mesh:

Unstick to Mesh

My current theory is that when I Detach From Actor the weld is not being detached correctly. If I untick Weld Simulated Bodies in the Attach Actor To Component, attachments work more than one time. However, this causes other issues as I would like them to be welded together.

Things I have tried that have not changed behavior

  • I have attempted to reset the root component to the correct static mesh on detachment
  • Using AttachActorToActor instead
  • Changed the order of operations on when I am Setting Simulate Physics to On/Off
  • Attempted both using a socket for attachment and not using a socket
  • Tried using the Event OnHit for the entire actor instead

Things I have tried that have changed behavior

  • Messed around with the colliders in the meshes themselves. This is the part that is stumping me the most as I am not sure why different collider types would be reacting differently. When I change the StickyMesh to a sphere collider instead of a cube some OnComponentHits work all the time but sphere to sphere OnComponentHits only trigger once. When using a cube collider for the StickyMesh however, all collisions only work once.

Any and all feedback and help would be appreciated! I am hitting my head against the wall with this one!

After digging around a little more in a source build of the engine I noticed that in AActor::DispatchPhysicsCollisionHit…

On the first collision ‘this’ AActor refers to the Sticky Gadgets which is expected. However after detachment, on the second collision ‘this’ AActor refers to the Sticky Gadgets parent, not the Sticky Gadget, which is why its OnComponentHit is never called.

I still have no idea why when the StickyGadget is getting hit it would be saying its hitting its parent though.