Advertisement

Crashing Unreal Engine with minimal effort

Started by August 22, 2017 10:34 AM
7 comments, last by MarcusAseth 7 years, 3 months ago

I need some help to understand what I'm doing wrong here x_x

Here's my step:

1) create a new C++ project with starting content, drop a door in the scene.

2)Add a C++ component to the door called OpenDoor

3)add a variable in the .h and initialize it in the .cpp  (code below)

When I compile this, the editor crash and any future attempt to open the project won't succede. What mistake did I made? Furthermore, if said mistake is made, is the project lost forever or there is a way to restore it? x_x  Cause if wathever silly mistake I've made, if it's all it takes to corrupt and lose an entire project, then I'm done with Unreal Editor... x_x

OpenDoor.h:


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "OpenDoor.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UOpenDoor : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UOpenDoor();

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

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

private:

	float DoorYaw;
	
};

 

OpenDoor.cpp:


// Fill out your copyright notice in the Description page of Project Settings.

#include "OpenDoor.h"
#include "GameFramework/Actor.h"

// Sets default values for this component's properties
UOpenDoor::UOpenDoor()
	:DoorYaw{GetOwner()->GetActorRotation().Yaw}
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


// Called when the game starts
void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();

	// ...
	
}


// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// ...
}

 

Most likely GetOwner() is crashing or returning nullptr. Don't call functions like that in the constructor, because you have no idea what state the object hierarchy will be in. The correct place to initialise any non-trivial values in UE4 is BeginPlay(). (Or maybe InitializeComponent, or similar.)

Advertisement

Kylotain covered the most likely culprit, so I'll focus on just this bit:

7 minutes ago, MarcusAseth said:

Furthermore, if said mistake is made, is the project lost forever or there is a way to restore it?

Open the file in a normal text editor and either fix the code or comment the offending code out. This should allow you to open the project in Unreal again.

Hello to all my stalkers.

Thanks Kylotan, I was starting suspecting the same thing.

@Lactose : I have removed all changes I had made from the .cpp and .h files, saved, closed VC and restarted UE, launched my project, but still getting the same error/crash before the projects even manage to finish to load. How is this even possible?

Any chance a copy of the offending file has been created in some cache folder and is still being used while my original is ignored?

Have you tried a rebuild in Visual Studio?

3 minutes ago, MarcusAseth said:

Any chance a copy of the offending file has been created in some cache folder and is still being used while my original is ignored?

Not that I know of.

What does your code look like after your recent changes?

EDIT: Or rebuild in VS, like Kylotan mentions :)

Hello to all my stalkers.

Advertisement

@Lactose: Here's the code (below)

As you can see I've removed all the things added by me.

I think I've just found the easiest way to break everything, try those 3 steps yourself, you'll see... :D

OpenDoor.h:


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "OpenDoor.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UOpenDoor : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UOpenDoor();

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

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

	
};

OpenDoor.cpp:


// Fill out your copyright notice in the Description page of Project Settings.

#include "OpenDoor.h"

// Sets default values for this component's properties
UOpenDoor::UOpenDoor()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


// Called when the game starts
void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();

	// ...
	
}


// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// ...
}

 

11 minutes ago, Kylotan said:

Have you tried a rebuild in Visual Studio?

Ops, I missed this reply, just tried and it fixed, thanks again @Kylotan!! :D

EDIT: did I've found a random way to zoom the emoticon above? I see it zoomed, wtf is wrong today with me and technology?! Breaking wathever I touch... ç_ç

This topic is closed to new replies.

Advertisement