Search code examples
unreal-engine4unreal-blueprint

UE4 Attach actor (or his component) to another actor (or his component)


So, the setup i have is simple. I'm making a VR darts game, sortof, using the default VR template, and i have a DartActor, with an attached ConeMesh (StaticMeshComponent) used for the dart, as well as a TableActor with an attached CylinderMesh (StaticMeshComponent) used for the dart board, as well as a RotatingMovementComponent.

When I detect an overlay between the two, I turn off physics on the dart (because otherwise it just bounces off) and try to attach it to the table actor. I have tried the following:

  • "attach actor to actor", when I try to attach the dart actor to table actor
  • "attach actor to component", when I try to attach the dart actor to TableActor's mesh component
  • "attach component to component", when I try to attach the DartActor's root component or mesh component to TableActor's mesh component or root component.

Neither of those worked well for me.

But disregarding that, turning off physics on the DartActor when an overlay is detected successfully fakes the dart sticking in the table. With one minor caveat - when the dart is seemingly stuck in the board, the board is still spinning underneath the dart.

I used the "Snap to Target" for both the location and rotation, and just kept "keep relative" for scaling on the "Attach" blueprint node.

What I'd like to have is, the dart actually sticking to the table, welding, and rotating with the table (dart board) while it's also rotating.

So, how do I do that?

I'm using UE4.27.2, if you need the blueprint screenshots just lemme know.


Solution

  • Ok, I fixed it.

    It turns out it was a combo of other misc slipups...

    1. The StaticMeshComponent needed to be the root component instead of the default RootComponent - for both the DartActor and TableActor
    2. I used AttachActorToComponent in the DartActor's Blueprint, using the DartActor's self and attaching to the TableActor's StaticMeshComponent
    3. In the actual AttachActorToComponent BP node, I used "Keep World" for all three things (location/rotation/scale)
    4. I kept the "Set simulate physics" to OFF on the DartActor itself, before attaching.

    And that's it, the darts are now sticking to the board and rotating along with the rotating board.