[C++] Detach From Parent crashes

Hi everyone,

I’m trying to detach a component, or just to attach it to another component. Unfortunately, whatever I do, this causes the editor to crash in PIE…

When I try to detach the component, I check if it exists :

if (temp->AttachParent != nullptr)
	temp->DetachFromParent();    

And I got this error :

Assertion failed : !bRegistered || AttachParent->AttachChildren.Contains(this)[File:D : \BuildFarm\buildmachine_++depot + UE4 - Releases + 4.7\Engine\Source\Runtime\Engine\Private\SceneComponent.cpp][Line:1093]

Attempt to detach SceneComponent ‘Cube’ owned by ‘Actor_0’ from AttachParent ‘Group_0’ while not attached.

Adn when I try to attach the component to another component, the editor just freeze and never get an error logs or whatever usefull crash logs.

Does anyone know what I am doing wrong ?

Hello,

Your code fails on the following assertion:

// Make sure parent points to us if we're registered
checkf(!bRegistered || AttachParent->AttachChildren.Contains(this), TEXT("Attempt to detach SceneComponent '%s' owned by '%s' from AttachParent '%s' while not attached."), *GetName(), (GetOwner() ? *GetOwner()->GetName() : TEXT("Unowned")), *AttachParent->GetName())

Thus, please check whether your Component is correctly registered and attached to Parent.

Hope this helped!

Cheers!

Hi,

Thanks for the answer. I just ran out of this issue, the problem was that I added another component with the same name that the one I tryed to detach.(I add components dynamically based on a file, so names aren’t manage in code)

I just had to change the name of one component to solve this issue.

This works fine now !

Cheers !