Download

How to re-parent a "GameObject"/"Actor" at run-time? (coming from Unity to Unreal)

I haven’t developed in Unity in a while, but it’s what I’m most familiar with. If I remember correctly, if you want to add an object already instanced in the game world to a player character (or any object) you could update the instanced object’s parent to have it’s transform coordinates be relative to your actor with the “hierarchy view”. Please correct me if this is wrong.

For my project in Unreal: I want a game object / actor to snap on to the player and move with them. I’m able to achieve the effect I want by new’ing up a component and attaching to my player in the Unreal Editor (not at run-time), but I don’t know what the best practice would be to make another game actor (or at least the mesh) become a “child” of the player actor at runtime.

Is there something similar in Unreal? I’m new, but I’ve experimented with AddToActor / AddToComponent and I’m not getting the result I want so far. It feels like it should be a simple solve.

The function you are looking for is AttachToComponent, it is an AActor function:


MyActorToReceiveTheAttachment->AttachToComponent(TheParentSceneComponent, TheAttachmentRules, TheSocketName)

With this suggestion I pressed on to try and load the engine symbols and debug exactly why this wasn’t working for me.

It turned out that my main issue was that I needed to have my attachment rules set correctly to have the new physics body behave the way I wanted (specifically: set the “weld” bool to true). Previously it was failing to attach, but there was no log or result to debug with until I dove into the engine code.

Thanks!