Tag Archives: [UE4]

Datatable is a component of Excel which is provided by UE4 engine

Udatatable is a component provided by UE4 to read and write files. The advantage is that you don’t need to write the logic related to C + + STL API, such as fopen and Fclose, to avoid the differences between different platforms; The disadvantage is that the DataTable function you want is not implemented, so you have to use fopen to play it yourself

Reading and writing excel needs to be exported as a CSV file. At present, *. XLS format is not supported

In the following official documents, there is no specific description about the usage of defining line structure with C + + Code:

If a DataTable is created from a blueprint, then the row structure structure can also use the structure component provided by UE4. The creation method is: add new blueprints structure, and then set the row structure in this structure

If you create a DataTable with C + + code, you can directly create a new C + + class and choose to inherit the DataTable. In addition, ftablerowbase can be directly defined in the header file of the custom datatable, for example:

#pragma once

#include "Engine/DataTable.h"
#include "CharactersDT.generated.h"

USTRUCT(BlueprintType)
struct FLevelUpData : public FTableRowBase
{
	GENERATED_USTRUCT_BODY()

public:

	FLevelUpData()
		: XPtoLvl(0)
		, AdditionalHP(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;

	/** Extra HitPoints gained at this level */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		int32 AdditionalHP;

	/** Icon to use for Achivement */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		TAssetPtr<UTexture> AchievementIcon;
};

Using excel to store gameplay data – DataTables

https://wiki.unrealengine.com/Using_excel_to_store_gameplay_data_-_DataTables

Data Driven Gameplay Elements

https://docs.unrealengine.com/latest/INT/Gameplay/DataDriven/index.html

Driving Gameplay with Data from Excel

https://forums.unrealengine.com/showthread.php?12572-Driving-Gameplay-with-Data-from-Excel

Methods for manipulating DataTable with blueprints.
Unreal Engine, Datatables for Blueprints (build & Use)

Excel to Unreal

https://www.youtube.com/watch?v=WLv67ddnzN0

How to load *.CSV dynamically with C++ code

If you have few tables you can use this self-contained DataTable, if you have many tables and will change them frequently, then you have to manually operate one by one in the UE editor after each change, so it is recommended to load *.csv dynamically in C++:.

FString csvFile = FPaths::GameContentDir() + "Downloads\\DownloadedFile.csv";
if (FPaths::FileExists(csvFile ))
{
	FString FileContent;
	//Read the csv file
	FFileHelper::LoadFileToString(FileContent, *csvFile );
	TArray<FString> problems = YourDataTable->CreateTableFromCSVString(FileContent);

	if (problems.Num() > 0)
	{
		for (int32 ProbIdx = 0; ProbIdx < problems.Num(); ProbIdx++)
		{        
			//Log the errors
		}
	}
	else
	{
		//Updated Successfully
	}
}