SetupAttachment not working

Hi, I’m trying to create a C++ Actor with a Procedural Mesh Component attached to it. I followed the instuctions on many sites including the Epic’s official documentation (https://docs.unrealengine.com/latest/INT/Programming/Tutorials/Components/1/). This is my resluting code:

It compiles and the editor opens with no problem, but when I hit play it crashes:

Ensure condition failed: !bRegistered [File:D:\Build++UE4+Release-4.16+Compile\Sync\Engine\Source\Runtime\Engine\Private\Components\SceneComponent.cpp] [Line: 1575]
SetupAttachment should only be used to initialize AttachParent and AttachSocketName for a future AttachTo. Once a component is registered you must use AttachTo.
[2017.11.07-20.18.56:617][ 70]LogOutputDevice:Error: Ensure condition failed: !bRegistered [File:D:\Build++UE4+Release-4.16+Compile\Sync\Engine\Source\Runtime\Engine\Private\Components\SceneComponent.cpp] [Line: 1575]
[2017.11.07-20.18.56:618][ 70]LogStats: FDebug::EnsureFailed - 0.001 s
UE4Editor.exe ha desencadenado un punto de interrupción.

Any ideas?

Are you doing this in the constructor?

Yes, this is the full Actor’s constructor

Solved!
I was accidentally deleting the pointer where the Actor was stored, I’m not sure why but it made it chrash (may be the build-in garbage collector assuming my Actor was no longer used?).

Fixed the code and now it’s working.