Creating Datatable asset from JSON file The Dialogue system based on CSV composed Datatable seemed working well for a while. But as the size of the dialogue gets bigger, we slowly realized that the current system is hard to catch the entire flow of dialogue, and requires too much time to compose. So we needed to find some another way. After some research, we found that Twine seems reasonable. Lucky to us, we found that there is a open source javascript that can export Twine based story as JSON file. Until this time, I thought this won't take too long because UE4 already has it's own JSON parsing pipeline. (Reference : Twine to JSON converter) Top image is a Phrase I wrote from Twine and bottom image is a JSON file exported from Twine by using javascript I mentioned above. In Unreal, Json is a data which composed as array of fields. Each field can have two types of properties and values. Non-Array type, and Array type. Non-Array type is a single data(Single data per property), and Array type is array type data(Multiple data per property). In this example, pid, name, content is a Non-Array type. 'pid' : id of each phrase. 'position' : phrase's position in Twine. I think this one is meaningless. 'name' : name of the Phrase 'content' : content of the phrase. including variables, functions you used. Will parse script, gives_Arr, startPriority, and delegates. And tags, childrenNames is a Array type. 'tags' : tag. Will parse prereq_Arr. 'childrenNames' : phrase's children list. Will parse optname_Arr. According to the Unreal's document, to import JSON file as an asset, we need an exact same structure as the JSON file we want to use. So I made exactly same structure as JSON file I got which has pid, position, and etc. But when I importing that file into the editor, it failed. For some reason, I couldn't get any information from that file. Well... it just tossed me empty Datatable. I tried every possible solution I can find, but none of them worked well. There was only one way left to me to get through this problem. Creating my own Unreal JSON parser. I'll skip all the stories of my failure. I just hope this can help anyone who is trying to parse JSON to Unreal or create Datatable dynamically. Adding custom C++ JSON parsing pipeline to Unreal (Source, How to use) I know most of you wrote C++ codes in Unreal for the first time had a lot of troubles. And this was my first time. First time for both using JSON and Unreal in my life. This is how I did to create Datatable for our dialogue system. If anyone who don't know how my Phrase and Option structure look like, check my previous post before you read more. I strongly recommend you to download source and How to use document. It will be much more helpful than my explanation. Basically what I did for parsing JSON is pretty much same as Unreal's JSON parsing pipeline. I've skimmed their method and modify it to my way. In this post, I'm going to explain how did I create 'Phrase' Datatable from JSON string. (I won't post Option structure since it's quite similar to this.) First. You need to add JSON related functionality to Unreal, you need to add two modules to your ProjectName.Build.cs. "Json" and "JsonUtilities" are those. (Without these, you will get compile error when you include "Json.h", "JsonSerializer.h".) After that, create Actor class which has pointer of Datatable and a string to store a name of Json file we will serialize as its members. You are going to need Json.h, JsonSerializer.h and FileManager.h. If you are not interested in creating Datatable, you can skip that part. Second. I created FJsonPhraseData structure. Be aware of inheriting public FTableRowBase. To create a Datatable int row base, this is mendatory thing. Third. Let's start parsing!
0 Comments
Leave a Reply. |
AuthorHyung Jun Park ArchivesCategories |