How to fix repeated crash when loading Project?

After making a change to code project crashed while compiling in the editor. In the log I get this error each time:

[2017.07.03-03.30.08:924][ 0]LogWindows:Error: UE4Editor-Invert-2188.dll!AShip_Base::AShip_Base() [e:\documents\dropbox\personalprojects\unrealprojects\invert\source\invert\private\ship_base.cpp:18]

which refers to this section of code in the constructor of the Pawn class I was working on.

	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
	SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
	// RootComponent = SphereComponent;
	SphereComponent->InitSphereRadius(500.0f);
	SphereComponent->SetCollisionProfileName(TEXT("Pawn"));

I tried to change the code in question and recompile, but I still get the same error, even after commenting out the most of the code in the constructor.

I’ve also tried removing contents from the Content folder, Changing the Intermediate folder to Intermediate.OLD, changing the Saved folder to Saved.OLD. None of that has worked. It seems like I just need to force a recomile, or delete a cache, but I can’t figure out how to do either of those. Anyone have any suggestions?

Are there any errors to go with the crash before it gives you the line of code?

Yeah, a few lines above that in the log I get this:

017.07.03-03.30.08:923][ 0]LogWindows:Error: === Critical error: ===
[2017.07.03-03.30.08:923][ 0]LogWindows:Error:
[2017.07.03-03.30.08:924][ 0]LogWindows:Error: Fatal error: [File:D:\Build++UE4+Release-4.16+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 3615]
[2017.07.03-03.30.08:924][ 0]LogWindows:Error: Default subobject SphereComponent RootComponent already exists for Ship_Base /Script/Invert.Default__Ship_Base.

Is this by chance coming from a blueprint that derives from your class?

I’m pretty sure it is.

Easiest way to fix it is to remove the offending blueprint. If that fixes the crash recreate it and the new one should be fine.

Edit: Are you attaching the sphere component to the root?

Tried, still crashes, with the same error.

What’s the full source of the constructor?

AShip_Base::AShip_Base()
{
// 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;

	AutoPossessPlayer = EAutoReceiveInput::Player0;

	//RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("NewRootComponent"));
	SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
	 RootComponent = SphereComponent;
	SphereComponent->InitSphereRadius(500.0f);
	SphereComponent->SetCollisionProfileName(TEXT("Pawn"));

	Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
	Mesh->SetupAttachment(RootComponent);

	// Setup the camera boom
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(RootComponent);
	CameraBoom->TargetArmLength = 750.0f;
	CameraBoom->bUsePawnControlRotation = false;

	// Set up the camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	//FollowCamera->AttachToComponent(CameraBoom, USpringArmComponent::SocketName);
	FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
	FollowCamera->bUsePawnControlRotation = false;

	// Set up the Ship movement
	//ShipMovement = CreateDefaultSubobject<UShipMovement>(TEXT("ShipMovement"));
	//ShipMovement->UpdatedComponent = RootComponent;
}

The code may have changed slightly as I’m still trying to see if there’s something I can do from VS

Same error with that code? What did the constructor look like the last time it worked?

I believe it looked like this:

AShip_Base::AShip_Base()
{
 	// 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;

	AutoPossessPlayer = EAutoReceiveInput::Player0;

	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
	//SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent"));
	//RootComponent = SphereComponent;
	SphereComponent->InitSphereRadius(500.0f);
	SphereComponent->SetCollisionProfileName(TEXT("Pawn"));

	Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
	Mesh->SetupAttachment(RootComponent);

	// Setup the camera boom
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(RootComponent);
	CameraBoom->TargetArmLength = 750.0f;
	CameraBoom->bUsePawnControlRotation = false;

	// Set up the camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	//FollowCamera->AttachToComponent(CameraBoom, USpringArmComponent::SocketName);
	FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
	FollowCamera->bUsePawnControlRotation = false;

	// Set up the Ship movement
	//ShipMovement = CreateDefaultSubobject<UShipMovement>(TEXT("ShipMovement"));
	//ShipMovement->UpdatedComponent = RootComponent;
}

I’ve compiled, and recompiled the code in Visual Studio before and after the crashes. I’ve even commented out the entire constructor, changes I made to other scripts, and then recompiled. It still crashes.

This sounds like you’ve got something, a blueprint, something saved maybe in a map based on this actor that is expecting the RootComponent to be of one type but because you’ve changed it it’s throwing an error. I highly suggest ensuring you’ve removed any blueprint versions of this class and any maps that might have the class and try running it.

Deleted the BP asset, and changed the name of the rootcomponent so there’d be no name conflicts. Still crashes with the same error

That was brilliant. Hadn’t thought to get rid of the dll. Thanks a million!

This looks like it wouldn’t compile. I’d go back to whatever state it was working, confirming with a build that works, and then try to make the changes again.

Hi, I am a complete rookie in this programming stuff, but with a trial and error process and a lot of lucky, looks like I could solve a problem similar to yours.

Try this:

  1. Save in a .zip and remove the .dll file that gives you the problem (UE4Editor-Invert-2188.dll). I think it is located in folder “ProjectName”\Binaries\Win64
  2. Open the project with UE4 (in my case it opened with no errors).
  3. Compile in the UE4 editor.
  4. Close the project.
  5. Unzip the .dll file
  6. Re-open the project and check if it works properly.

I hope it works!

Glad I could help!