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
Implementing dissolving shader
Actually, for this one, I don't have much things to say. All you have to do is using texture as opacity mask with any trigger function, and blend the result with the base. For this one, I used simple grey-sandstone looking texture for the base color, fractal alpha texture for opacity mask, and simple sine function for the trigger. By utilizing different trigger functions or alpha textures, you will be able to create various dissolving material easily. Sep 28th 2016
Implementing dialogue system based on data table in Unreal Engine 4 is not a difficult task because they have already implemented core functionality. What I have referenced is Implementing Data Driven Gameplay Although there are several issues which will prevent you from building efficient and flexible dialogue system, this method is quite simple and easy to follow The Dialogue system of ours is based on 3 core components. Phrase, Option, and Prerequisite. 1) Phrase - Phr_name : Name of this phrase - Script : A script that each phrase will show you - Prereq_Arr : A list of prerequisites that each phrase requires. If there is any prerequisite not satisfied yet, you can access neither phrase nor option that will lead you to this phrase - Gives_Arr : A list of prerequisites that each phrase will release. When you enter this phrase, it can let you see a certain phrase or option that will lead you to that phrase. - Optname_Arr : A list of option phrases. Each phrase can have maximum 4 options that will lead you to the next phrase. - Startprioirity : Starting point of the phrase. The higher the rank, the higher its priority is. 1 is the highest rank and 0 has no rank. You can consider this as an index of root node of phrase tree. - Delegate : A string that "calls a function" as its parsed by the system. It goes through switch statement and calls code based on it 2) Option - Opt_name : Name of this option - Script : A script that each option will show you. This is only can be seen from certain phrases. - Target_phraseindex : Index of phrase that option is targeting. When you choose this option, it will lead you to the phrase of this index. 3) Prerequisite - Index : Index of this prerequisite - Prereqs : List of prerequisite What I did - Composed 3 core structures - Find a way to parse data to Datatable asset Issues & Problems - Datatable row structure requires something it can identify each row. This is why I add Phr_name and Opt_name. - Datatable can't handle custom or nested structure. It cannot referencing or pointing other data from data it has. - Access by name only. Blueprint only allows us to access to the Datatable by drop down list selection. So you can't get certain Datatable by name or something else. This will lead you to unpleasant hard coding. - Datatalbe is a static, read-only asset because UE treats structure as just a datatype. Datatable's row structure is a structure type too. You can create Datatable asset from CSV file by using Excel or something, but to create it dynamically, you need some more extra works. - The reason I separated Phrase and Option is because UE does not allow us to create structure or class that holds pointer of same structure. It should have been something like linked list, but I don't know how to do that in Unreal. ex) struct MyStruct { int blah; OK float blahblah; OK MyStruct* pointer; NOT OK }; |
AuthorHyung Jun Park ArchivesCategories |