How can I detach an Actor's RootComponent from another Socket?

I think what you can do is get your root component and call

DetachFromParent()

This is called from the component itself… not the Actor.

The AttachTo or AttachRootComponentTo method sets the object as the parent of the object you are attaching.

I’ve attached one of my Blueprints programmatically to my Character’s RightHandSocket using the following:

//TestCharacter.cpp

MyItem = GetCurrentlyEquippedItem(); //Gets the thing to attach
MyItem->AttachRootComponentTo(this->Mesh, "RightHandSocket", EAttachLocation::Type::SnapToTarget); // Attaches the item to my character's right hand.

However, I’d like to detach it from that socket later on, in the case of the player dropping the item. I haven’t been able to find anything in the AActor page that resembles “detaching”, so I wonder if I’m looking in the wrong spot?

#The Solution

MyItem->DetachRootComponentFromParent();

Doesn’t matter what/who the parent is :slight_smile:

#Actor.h

/** 
 *  Detaches the RootComponent of this Actor from any SceneComponent it is currently attached to. 
 *   @param bMaintainWorldTransform	If true, update the relative location/rotation of this component to keep its world position the same
 */
UFUNCTION(BlueprintCallable, meta=(FriendlyName = "DetachActorFromActor"), Category="Utilities|Orientation")
void DetachRootComponentFromParent(bool bMaintainWorldPosition = true);

Rama

Okay thanks. I’ll try it. I thought the parent would be something other than what I attached it to.

I´m facing a similar problem

attaching like this
MyItem->AttachRootComponentTo(this->Mesh, “RightHandSocket”, EAttachLocation::Type::SnapToTarget);

works properly

but
MyItem->DetachRootComponentFromParent();

seems not being working.
I would expect MyItem to get freed in the scene, but keeps moving attached to my character

any thoughts?
Thanks in advance