Crash: Can't get Data Tables working

Here are the steps I have followed, and it crashes every time. I create a new, blank project.

I click “Add code to project”, choose an Empty class and give it a name (CardDetail). I click the button to open in VS2013, which it does. I hit “build solution” in VS2013, switch back to the UE4 editor and can run the game without issue.
The code created is:
CardDetail.cpp

#include "Blank.h"
#include "CardDetail.h"

CardDetail::CardDetail()
{
}

CardDetail::~CardDetail()
{
}

CardDetail.h

#pragma once
    
/**
 * 
 */
class BLANK_API CardDetail
{
public:
	CardDetail();
	~CardDetail();
};

I then cut and paste the code from the official documentation into the .h file, after the #pragma, leaving the rest intact:

/** Structure that defines a level up table entry */
USTRUCT(BlueprintType)
struct FLevelUpData : public FTableRowBase
{
	GENERATED_USTRUCT_BODY()

public:

	FLevelUpData()
		: XPtoLvl(0)
		, XP(0)
	{}

	/** The 'Name' column is the same as the XP Level */

	/** XP to get to the given level from the previous level */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		int32 XPtoLvl;

	/** This was the old property name (represented total XP) */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		int32 XP;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		TAssetPtr<UTexture> Asset;
};

I get an error about missing ‘#include “CardDetail_generated.h”’, which I insert. This time 'Build solution" works.

I duplicate the comma-separated file listed in the official example. Back in the UE4 Editor, I drag and drop my .csv file onto the Content Explorer, but only the default GamePlayTagTableRow option exists under “DataTableOptions” in the importer dialog. I hit “Save All”, shut the editor, reopen the project, and the editor crashes.

Log is attached. (Cast of NULL to package failed)

What have I done wrong?

OK! I found a solution! The default constructor provided by the wizard is invalid. The code needs to force the .h file to be constructed each time.

CardDetail.h:

#pragma once
#include "CardDetail.generated.h"

/** Structure that defines a level up table entry */
USTRUCT(BlueprintType)
struct FLevelUpData : public FTableRowBase
{
	GENERATED_USTRUCT_BODY()

public:

	FLevelUpData()
		: XPtoLvl(0)
		, XP(0)
	{}

	/** The 'Name' column is the same as the XP Level */

	/** XP to get to the given level from the previous level */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		int32 XPtoLvl;

	/** This was the old property name (represented total XP) */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		int32 XP;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		TAssetPtr<UTexture> Asset;
};


UCLASS(Abstract, CustomConstructor)
class UCardDetail : public UObject
{
	GENERATED_UCLASS_BODY()

	UCardDetail(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) {}
};

In the .cpp file just remove the references to the constructor and destructor.

Hi ,

I am glad to see that you were able to find a solution. I just wanted to provide some additional information about why this is necessary.

In order for the UnrealHeaderTool and UnrealBuildTool to recognize a USTRUCT, it must be contained within a header file that contains a UCLASS macro. As you noticed, without the UCLASS in place, the Editor crashed when opening the project. If you had selected any other option as the parent of your new class (eg. Object), the header file that would have been created for you would have automatically included the UCLASS macro and you would not have seen the crash.

Thanks for clearing that up, .

In other threads I have created while struggling through this issue I mention that the only reason I’m doing this in C++ is because it’s the only way - Blueprints do not support creation of this kind of structure to my knowledge. As a result I “missed the memo” regarding the necessity to select a non-blank class when adding the code to the project. Might I suggest you put something in that vein in the unrealdocs documentation? That reference was my point of entry into the world of C++ in UE4 and I’m sure most Blueprint guys like myself had the same problem with not having any idea how to get the thing working despite the example that everyone else says “explains everything”.

I think the best way would be to list an entire .h file as the sample code rather than just the USTRUCT portion of it for that reason alone. People are lazy and will cut 'n paste in the manner I did, and then pull their hair out for hours because there’s no hint about the missing bits that we actually have no interest in learning because the rest of what we want is (or should be) handled by the Blueprint system. There should be no need for people to have to immerse themselves in C++ just to define one structure.

I’d also like to suggest that you guys find a way to not crash the editor if it can’t load the USTRUCT (or anything else, for that matter). Some of the errors I’ve seen with this problem cause issues with the Blueprint nodes even if you fix the .h file, and if you can’t load the editor you can’t fix the nodes that are faulty without going through your backups. So you mainly end up wasting time chasing your tail, and I’d like to think there is a way for the editor to fail to load a little more gracefully. :slight_smile:

We agree that crashes are undesirable, and we do our best to find ways to prevent them. I just tried to reproduce this issue in our latest internal build of the Engine and I did not see the crash happen, so it looks like you will be seeing some improvement in this area in particular in future versions of the Engine.

With regards to the information on the page you linked, I have submitted a request to our documentation team to see if that can be improved, specifically with regards to the need to have the USTRUCT contained within a header that includes a UCLASS macro (UEDOC-341).

Thank you, !

I think it is disappointing that the process of working with a CSV asset in blueprint requires everybody to write code where it would be more useful if there was a generic way to pull apart the CSV in blueprints.

Hi tomofnz,

Blueprint structures are available, but they are still very much a work in progress. The goal for those is to make them functionally identical to USTRUCTs, and hopefully even a little bit easier to use. We are still working on them, but support for CSV files and data tables is planned.