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
}
}
Similar Posts:
- [Solved] MYSQL add foreign key error: Referencing column ‘xx’ and referenced column ‘xx’ in foreign key constraint ‘xxx’ are incompatible.
- This Row already belongs to another table error when trying to add rows?
- C++: The usage of spanactor in [UE4]
- [Solved] Java.nio.file.AccessDeniedException is reported when moving excel files in Tomcat project
- UNREFERENCED_ The role of parameter
- How to Solve Datatable field value is empty Error
- Python ImportError: No module named win32com.client [How to Solve]
- Php7 + phpexcel table export failed net:: err_ INVALID_ RESPONSE
- BadZipFile: File is not a zip file [How to Solve]
- [Solved] Object references an unsaved transient instance – save the transient instance before flushing