Jump to content
  • Advertisement
MarcusAseth

Crashing Unreal Engine with minimal effort

This topic is 480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

	// ...
}

 

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
Advertisement

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.)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

@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);

	// ...
}

 

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
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... ç_ç

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!