Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How can I use my own row struct to create my own datatable?

USTRUCT(BlueprintType) struct FJsonData : public FTableRowBase { GENERATED_USTRUCT_BODY() public: FJsonData() :pid(0) {} UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "JPhrase") int32 pid; };

UCLASS(Blueprintable) class BPATTEMPT_API UJson2DataTable : public UDataTable { GENERATED_UCLASS_BODY()

public: UPROPERTY(EditAnywhere, Category = "My Object Properties") FJsonData fjsonData; };

As you can see, I have my own structure, and I want to create my own datatable in C++ which will use FJsonData as it's row structure. How can I set my own structure as DataTable's row structure? Anyone has Idea? I've searching google for several days, but there's no answer.

What I'm trying to do is parsing Json data and create a datatable asset with it from C++ so that I can use it in Blueprint level.

Product Version: UE 4.12
more ▼

asked Nov 03 '16 at 03:28 AM in C++ Programming

avatar image

1 1 2 2

avatar image Shadowriver Nov 03 '16 at 08:14 AM

What exactly do you want import json to asset or directly use json data in asset?

avatar image ArtainEX Nov 04 '16 at 12:46 AM

I want to create a datatable from the data I parsed from Json. Which means, I want import Json in C++ level, and creates an asset.If there's any way I can creates Datatable with the data I parsed from Json, that will do too. Actually, Unreal provides functionality to import Json with certain structure to creates datatable. But when I tried that, it didn't work properly. Most of the values are wrongly parsed, If you know how to do that, please tell me. Thanks!

avatar image ArtainEX Nov 03 '16 at 07:02 PM

Never mind! I found the way to do that. Will upload how I did that to my website someday. What I did is just implementing my own json parser so that it can add data to the datatable which is already allocated to the actor


avatar image Malloc007 Nov 09 '16 at 05:40 AM

Hello,ArtainEx! Can share give your websitem,what your give may be is very useful to me,Thank you!

avatar image ArtainEX Nov 11 '16 at 01:38 AM

Well, basically what I did is creating datatable in UE4 editor level, and allocate it to my actor. Then actor creates the datatable contents based on the structure I defined. What I referenced is Unreal's Json parser itself. I'm in the middle of my semester, so detail explanation will be uploaded somewhere around December

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Did you read this? https://wiki.unrealengine.com/Using_excel_to_store_gameplay_data_-_DataTables


Here's the creation of the datatable using custom struct.

Although, I'm using a C++ struct here, this method will work for blueprint structs as well.

 struct FExampleDatatableRow : public FTableRowBase
     UPROPERTY(EditAnywhere, BlueprintReadWrite)
     FString SomeVar;

alt text

alt text

And to get data from such data table in C++:

 UDataTable* DataTable; // populate it however you want
 const FName RowName = FName("SomeRow");
 FExampleDatatableRow* FoundRow = DataTable->FindRow<FExampleDatatableRow>(RowName, "");

more ▼

answered Nov 10 '16 at 12:42 PM

avatar image

1.2k 20 23 40

avatar image ArtainEX Nov 11 '16 at 01:40 AM

Thanks for reply, and yes I did. But this is just a reference for how to use datatable which is already created, not creating new datatable.

avatar image Atheist91 Nov 11 '16 at 11:13 AM

Alright, i've edited my comment and changed it into an answer. Hope this helps.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

UE4.12 has some troubles with importing UDataTable from JSON. Try switching to 4.13 - all of my problems have gone after this switch.

Regarding Json import, I did the following.

1) Locate row structure:

     UScriptStruct* ImportRowStruct = LoadObject<UScriptStruct>(nullptr, TEXT("/Game/Blueprints/RowStruct.RowStruct")); // I used script structure to allow data table to be used from blueprints without any C++ game code

2) Create data table:

     UPackage* NewPackage = CreatePackage(nullptr, *PackagePath);
     EObjectFlags Flags = RF_Public | RF_Standalone;
     UDataTable* NewTable = NewObject<UDataTable>(NewPackage, UDataTable::StaticClass(), TableName, Flags);
     NewTable->RowStruct = ImportRowStruct;

3) Store Json to a file. Save Json file name inside new data table:


4) Call re-import for this table, so all Json data will be imported into the data table

     FReimportHandler* ReimportFactory = NewObject<UReimportDataTableFactory>();

The code has some capabilities for updating existing table using reimport, which are not listed here. Using DataTableFactory simplifies workflow a lot. For instance, if you'll update contents of the Json file, it will be automatically reimported into the engine (with a prompt to user).

Hope this helps.

more ▼

answered Nov 13 '16 at 01:34 PM

avatar image

79 1 3 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question