CreateDefaultSubobject crashes the editor

Hello, I’ve been trying to get my Random Level Generator to create actor components during construction, but I can’t figure out how to do it. I can easily do it in BP but I now want to convert it to code. The following code is crashing. There’s more code after this line that sets the actor class / create the child…etc but I’ve left it out for now. I’ve spent 4 hours trying to figure this out but can’t find an answer. All the other examples I can find don’t have anything extra. I did read a few posts talking about the need to declare classes in the construction script, but I’m not sure what that means. Any help would be GREATLY appreciated!

void ARandomLevelGenerator::OnConstruction(const FTransform& Transform)

 UChildActorComponent* Rooms = CreateDefaultSubobject<UChildActorComponent>(TEXT("TestObject"));
 // Extra stuff...

You need to use NewObject<> + RegisterComponent() in the OnConstruction method, only use CreateDefaultSubobject in your contructor