UE crushes when trying to open my project

I wrote only 2 classes, and already got a fetal crush, as the title say, whenever i open my project in the editor, the editor crushs. the classes are as follows:

###APlayerPawn.h:####

#include "BodyShapeComponent.h"
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "PlayerPawn.generated.h"

UCLASS()
class SHAPETOSS2_API APlayerPawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	APlayerPawn();

	UPROPERTY(VisibleAnywhere, Category = "Mesh")
	UBodyShapeComponent* shape;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};

###APlayerPawn.cpp:###

#include "PlayerPawn.h"

// Sets default values
APlayerPawn::APlayerPawn()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	
	shape = new UBodyShapeComponent("Sphere");
}

// Called when the game starts or when spawned
void APlayerPawn::BeginPlay()
{
	Super::BeginPlay();
}

// Called every frame
void APlayerPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

// Called to bind functionality to input
void APlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
}

###BodyShapeComponent.h:###

#include "CoreMinimal.h"
#include "Components/StaticMeshComponent.h"
#include "BodyShapeComponent.generated.h"

UCLASS()
class SHAPETOSS2_API UBodyShapeComponent : public UStaticMeshComponent
{
	GENERATED_BODY()
	
public:
	/** Default Constructor - create a sphere */
	UBodyShapeComponent();

	/** Constructor - name is the meshe's file name */
	UBodyShapeComponent(const FName name);

protected:
	// The Folder in which all the mesh files are located. Duh.
	const FName MESHES_PATH = "/Game/Meshes/";
};

###BodyChapeComponent.cpp:###

#include "BodyShapeComponent.h"

UBodyShapeComponent::UBodyShapeComponent(const FName name) :Super()
{
	FString path = MESHES_PATH.ToString() + name.ToString();
	UStaticMesh* tmpMesh = LoadObject<UStaticMesh>(nullptr, *path);
	SetStaticMesh(tmpMesh);
}

UBodyShapeComponent::UBodyShapeComponent() {
	UBodyShapeComponent("Sphere");
}

Whenever I try to open my project in the Unreal Editor, it crushes with the following error:

Fatal error: [File:D:\Build\++UE4+Release-4.16+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 2450] 
UObject(const FObjectInitializer&) constructor called but it's not the object that's currently being constructed with NewObject. Maybe you trying to construct it on the stack which is not supported.


UE4Editor_Core!FDebug::AssertFailed() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:349]
UE4Editor_CoreUObject!UObject::UObject() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:2451]
UE4Editor_Engine!UActorComponent::UActorComponent() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\components\actorcomponent.cpp:146]
UE4Editor_Engine!USceneComponent::USceneComponent() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\components\scenecomponent.cpp:68]
UE4Editor_Engine!UPrimitiveComponent::UPrimitiveComponent() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\components\primitivecomponent.cpp:156]
UE4Editor_Engine!UMeshComponent::UMeshComponent() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\components\meshcomponent.cpp:14]
UE4Editor_Engine!UStaticMeshComponent::UStaticMeshComponent() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\components\staticmeshcomponent.cpp:172]
UE4Editor_ShapeToss2_124!UBodyShapeComponent::UBodyShapeComponent() [c:\users\paz\documents\unreal projects\shapetoss2\source\shapetoss2\bodyshapecomponent.cpp:5]
UE4Editor_ShapeToss2_124!UBodyShapeComponent::UBodyShapeComponent() [c:\users\paz\documents\unreal projects\shapetoss2\source\shapetoss2\bodyshapecomponent.cpp:14]
UE4Editor_CoreUObject!UClass::CreateDefaultObject() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:2687]
UE4Editor_CoreUObject!UObjectLoadAllCompiledInDefaultProperties() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:816]
UE4Editor_CoreUObject!ProcessNewlyLoadedUObjects() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:894]
UE4Editor_CoreUObject!TBaseStaticDelegateInstance<void __cdecl(void)>::ExecuteIfSafe() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:1027]
UE4Editor_Core!TBaseMulticastDelegate<void>::Broadcast() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\delegates\delegatesignatureimpl.inl:937]
UE4Editor_Core!FModuleManager::LoadModuleWithFailureReason() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\modules\modulemanager.cpp:479]
UE4Editor_Projects!FModuleDescriptor::LoadModulesForPhase() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\projects\private\moduledescriptor.cpp:421]
UE4Editor_Projects!FProjectManager::LoadModulesForProject() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\projects\private\projectmanager.cpp:60]
UE4Editor!FEngineLoop::LoadStartupModules() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2470]
UE4Editor!FEngineLoop::PreInit() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:1896]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\launch.cpp:127]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:134]
UE4Editor!WinMain() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:210]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253]
kernel32
ntdll

I have no idea what has gone wrong (i didn’t even know the editor itself could crash because of bad code) and didn’t find anything of that sort online. Any help would will appreciated.

Hey there, the problem is there:

shape = new UBodyShapeComponent("Sphere");

you can’t use new in UE 4 and especially on the Constructor, try this instead:

shape = CreateDefaultSubobject<UBodyShapeComponent>("Shape");
shape->SetupAttachment(RootComponent);

Thanks for the quick reply!
It still doesn’t work for me, but I would like to know why isn’t the use of the ‘new’ keyword allowed in Unreal?

The same error as before is showing and I did not use new anywhere else.

Because Unreal uses his own Garbage Collector and macros to make things work. Do you get the same error? Do you use new on any other place?

Another thing, you can’t really typical parameter constructors like you have here:

UBodyShapeComponent::UBodyShapeComponent(const FName name)

Can you show me what you put in the APlayerPawn constructor?

if you commend this:

FString path = MESHES_PATH.ToString() + name.ToString();
UStaticMesh* tmpMesh = LoadObject<UStaticMesh>(nullptr, *path);
SetStaticMesh(tmpMesh);

Does it still crash? My guess is that the error is there.

It crushes even with the UBodyShapeComponent Constructor commented.

The code i currently have in the APlayerPawn Constructor is this:
APlayerPawn::APlayerPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;

	shape = CreateDefaultSubobject<UBodyShapeComponent>("Shape");
	shape->SetupAttachment(RootComponent);
}

Could the problem be from outside the code? Perhaps something in the project settings?

The call stack of the crash tells that the crash comes from the BodyShapeComponent, can you send me the cpp and h for the component and the pawn?

I’m sorry for the long response time. I didn’t have much time this week to work on this project, but i’ve found the problem.
The problem was the constructors for the UBodyShapeComponent, as you said; I commented the whole constructor (not only the code within it), as well as the decleration in the .h file, and now it works (as in the editor opens).


Thank you very much xlar8or for all your help with this.

No problem :slight_smile: