Editor Crash on opening project

Bretonic
Tue, 18 Apr 2017 18:10:10 +0000
Editor Scripting

Adding following lines of code caused my project to crash:

for (int i = 0; i < ItemData.ItemAreas.Num(); i++)
	{
		ItemData.ItemAreas[i].ItemAreaCollisionBox = CreateDefaultSubobject<UBoxComponent>(TEXT("Item Collision Box"));
		ItemData.ItemAreas[i].ItemAreaCollisionBox->SetWorldScale3D(FVector(1.0f, 1.0f, 1.0f));
		ItemData.ItemAreas[i].ItemAreaCollisionBox->bGenerateOverlapEvents = true;
		ItemData.ItemAreas[i].ItemAreaCollisionBox->OnComponentBeginOverlap.AddDynamic(this, &ABaseItem::OnCollisionBoxEnter);
		ItemData.ItemAreas[i].ItemAreaCollisionBox->AttachToComponent(ItemRootTransform, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
	}

The OnCollisionBoxEnter function worked before adding loop.

That loop was located in the constructor ABaseItem::ABaseItem(), this is ABaseItem’s header:

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

#pragma once

#include "GameFramework/Actor.h"
#include "BaseItem.generated.h"

class ABaseItem;

USTRUCT()
struct CATALYST_API FItemArea
{
	GENERATED_BODY()

public:
	//UPROPERTY(EditAnywhere)
		//ABaseItem* OwnerItem;

	UPROPERTY(EditAnywhere)
		float ItemAreaDurability;

	UPROPERTY(EditAnywhere)
		UBoxComponent* ItemAreaCollisionBox;

	UPROPERTY(EditAnywhere)
		FTransform ItemAreaCollisionBoxTransform;

	UPROPERTY(EditAnywhere)
		FVector ItemAreaCollisionBoxExtent;


	FItemArea()
	{
		ItemAreaDurability = 100;
		ItemAreaCollisionBoxExtent.Set(50, 50, 50);
		ItemAreaCollisionBoxTransform.SetLocation(FVector(0, 0, 0));
		ItemAreaCollisionBoxTransform.SetScale3D(FVector(1, 1, 1));
		ItemAreaCollisionBoxTransform.SetRotation (FRotator(0, 0, 0).Quaternion());
	}



};

USTRUCT()
struct CATALYST_API FItemData
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere)
		FString ItemDisplayName;

	UPROPERTY(EditAnywhere)
		FStringAssetReference ItemMeshPath;

	UPROPERTY(EditAnywhere)
		FVector ItemMeshScale;

	UPROPERTY(EditAnywhere)
		TArray<FItemArea> ItemAreas;

	FItemData()
	{
		ItemDisplayName = FString(TEXT("Default Item"));
		ItemMeshPath = FString(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
		ItemAreas.AddDefaulted();

	}
};

UCLASS()
class CATALYST_API ABaseItem : public AActor
{
	GENERATED_BODY()

public:
	// Sets default values for this actor's properties
	ABaseItem();

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

	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	void SetData(FItemData InputData);

	UPROPERTY(EditAnywhere)
		bool DefaultItem;

	UPROPERTY(EditAnywhere)
		FItemData ItemData;

	UPROPERTY(EditAnywhere)
		UStaticMeshComponent* ItemMesh;

	UPROPERTY(EditAnywhere)
		USceneComponent* ItemRootTransform;
	UFUNCTION()
		void OnCollisionBoxEnter(UPrimitiveComponent * OverlappedComponent, AActor * OtherActor, UPrimitiveComponent * OtherComponent, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);

};

Sorry if that was to long, I’m just making sure I don’t miss an important detail.

As you can see I was creating multiple bindings on a UBoxComponent on a USTRUCT to a single function on a UCLASS which to be honest I doubted would work. However this caused an editor crash, that continued crashing the editor when I tried to launch the project even when the lines of code had been commented out. This brought up the Unreal Engine 4 Crash Reporter and told me: “You do not have any debugging symbols required to display the callstack for this crash.” The only way I found to launch my project was to delete the folders Intermediate and .vs and remove any dll or pdb files in Binaries>Win64 that ended with numbers. Even then if I tried to compile my code the project crashed again.

I hope that somebody could tell me what is causing this problem and how to fix it. It would also be nice if I could be given an alternative to the error causing loop but that would not be necessary as long as I can get the project to launch again.

2 posts - 1 participant