Download

Editor crashes when creating a new component in cpp.

It crashes on this line:


UProceduralMeshComponent* mesh_ = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("Mesh"));

I’v tried to add all those lines after it but it didn’t help:


mesh_->RegisterComponent();    	 
	mesh_->SetWorldLocation(GetActorLocation());
	mesh_->SetWorldRotation(GetActorRotation());
	mesh_->AttachTo(GetRootComponent(), "None", EAttachLocation::KeepWorldPosition);

The creation of the component happens inside a normal function and not inside the constructor.

I’v also tried with with this component: UStaticMeshComponent
And it gave the same results.

Ok changed it to:


UProceduralMeshComponent* mesh_ = NewObject<UProceduralMeshComponent>(this, "Mesh");

And now it works.