Best way to attach an actor to another actor

I’m working on a project where a player can customize a boat by placing interactive objects on it. I am wondering what is the best way to go about this is.

Based on my own reading, there seems to be two main ways to go about this
A: sockets, but those only seem to be available for skinned meshes
B: actor components

As sockets seem to only work with skinned meshes, I presume that making each interactable element an actor component, while annoying, would be the best option. That said, if someone has a better understanding of how this all works, I would greatly appreciate their input.

1 Like

I am looking for an exact same thing. I have multiple actors that are each a separate system that need to attach to a certain actor which moves them around, so I don’t want to convert all of them to components and sockets are bound to meshes rather than actors

Not sure what the OP is talking about, but skeletal or static meshes can have sockets.

You can attach an actor to another actor’s specific component / socket with “AActor::AttachToComponent”.

AActor::AttachToComponent | Unreal Engine 5.2 Documentation

I’m sure there is a blueprint version of it as well. If you want to attach to an actor with no visible mesh, you can set up an invisible collision-less mesh with a bunch of sockets, and stick it on the actor that everything needs to attach to.

I agree this is the way. Depending on what you mean the way @Shmoopy1701 has mentioned is a way to go about it simply and at low cost on performance. If you need more customized functionality than that then you want to look at creating a vector widget for players to use and define a load of behaviors with parent actor such as bounds of mesh and vice versa for the child actor. You could then spawn a socket at those locations or an actor component but an actor component will add a level of complexity you may not be ready for and may add more overhead than you want.

Dynamically spawning sockets can also add more prep work and you would need to think do i need that level of complexity and performance cost as you will need to dynamically adjust game parameters to adjust for this. If its more interactive and visual then the cost is negligible

I forgot to mention I have all the actors in the level editor and would like to attach them to another actor keeping the same relative location to them. I will lose the ability to set everything up in the level editor by attaching them to a manually predefined socket.

I was hoping your ‘dynamically spawning sockets’ is the solution but I could not find a way to do that in blueprints. Creating them manually and then moving them dynamically before attaching would also work, but I can only read from the sockets that are already created. Can you elaborate on what you meant?