HOW TO - JSON file LOADING & READING into Unreal Engine BLUEPRINTS!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to another episode of this short little tutorial Series where I'm going to be demonstrating how to use the Json and HTTP utility plugin in this episode I'm going to be showcasing how we are going to use functionality to load Json files what already exist on the users's machine into Unreal Engine and then we are able to read the data from those loaded Json files in a real engine we're going to cover all the nodes for getting data out of Json fil and some utility functions which allow us to check if Fields exist and to remove fields from already existing Json files so without any more talking let's get into the tutorial I wanted to pop in here real quick and just let you know that this tutorial and all the tutorials which are going to follow this episode are based on this plugin right here the Json and HTTP utility plugin a link to this plugin will be found in in the description below so if you would like to follow along or learn more about it you can find the link in the description below and now let's actually get into the tutorial so back in the engine as you guys can see I am back in the template project for the third person template as you can see it's the basic template everyone gets as soon as you start the engine and all of the logic which I'm going to show you today is going to be done in the third person character blueprint so if you just open open that up and all the logic is going to stem off from begin play so here is just the basic starting logic unreal provides you so you can have a movable character so we're going to leave this here off begin play and then off of that we're going to add on top our own custom logic so again as mentioned before in this episode we're going to be showcasing how to load data into un real engine so the only requirement for this will be you already must have a Json file present somewhere on your machine so in my case I have a Json file already set in the project directory so if I can show you right here so as you can see we're in the project directory as you can see in the same file where all of my other project files are there is a Json file called Json test data and if I open it up as you can see it's a very large Json data file with just lots of random data and the data from here is actually valerant character data um the way I got this was actually I used the built-in HTTP request node and I sent a request to an unofficial valerant API to request this data and then this is the data returned so what I did is I just requested that data saved it to a file and now I'm going to load it into engine again so before we close down this folder all we need is just the name of the file and the extension so select all of it and copy it so I press contrl + C so just copy it and keep it in there as we're going to need it in a second so now heading back into the engine back in the engine we're going to first node which we are going to use is called load file from disk so I I just do load file from this right like this what this node will do is actually attempt to load any text file from your machine into Unreal Engine you must note that any file you are trying to load must be a text file so it doesn't matter if it's do txt Json whatever it has to be a text file it cannot load anything else so yeah just remember must be text files so with the node already created drag away from file and type in make and then you'll see a new structure which which you can create what's called file data so just create that and then you'll have to provide a file directory and file name so for the file directory this is the path to the file you're trying to load so the reason why I placed my Json file in the project directory is because now all I can do is just type in get project directory and this will return the file the path to my directory so all I have to do is just connect conect this to this and now the load file from dis will know the path to where my Json file is stored now all I have to do is just provide the name of the actual file I want to load so in this case as I mentioned before that's why you should have copied the name because now all you have to do is just paste it Json test data and just like that I have loaded the file into engine and we might not know this yet but if I was to test it by printing out this string like this compiling saving and actually starting the game on the left hand side you'll see a debug message appear with the whole Json file with the all all of the contents of the Json file so let's test it there you go as you can see all of the content of that Jason file just appeared on my screen for a few seconds so we know it works okay so back in the blueprint we can delete the print string for now and now we have the raw string data but we we can't really do much with raw string data unless we want to manipulate directly strings but that's not really helpful so what now we can do is use that another node called string to Json object and as it says on the tin what it does is it takes the raw string data and attempts to convert it into a usable Json object but you have to remember the caveat here is you have to provide a file which is formatted in a Json style or else it will not be it will fail to convert it into adjacent object so the loaded file must be a Json file for this this node to convert it into adjacent object okay so now we converted it into adjacent object we can now manipulate the data within the loaded Json file as we would any other Json file in engine so for example let me pull up the Json file again and as you can see in the Json file we are actually provided with two pieces of data uh two fields of data which is a status which is a number field and an array field of type data and the array field of type data contains all of the actual data within it as an array and then the status is just a single number field this is just how the Json file is provided when you request it using a HTTP request from The Unofficial valerant API so just to test let's see let's try to pull the status field so assuming everything is correct if I try to pull the status field I should be returned with the value 200 in Unreal Engine so back in engine now as you can see I've loaded the file and converted into Json object so now I can pull out from here and try and use the node try get number field and now it'll ask me for a field name so you have to always make sure you provide the correct field name as it's stated in the Json file right here so I'm looking for status so I'll will copy it just to be sure I'll do contrl c and then back in the field name just paste it and now if I try to do a print string from here and connect number date into the print string like this and compile and save now when I start the game on the top left of their viewport we should see a debug which says 200 so let's test it the right is right there 200 okay so now back in the blueprint graph so we know it loaded correctly and we debugged the value we could also do a success check here so using a branch so then if the print string if something went wrong we would all we would go from false but if everything was correct we'll always come out from true but personally I rather testing stuff in engine rather than just running branch checks so I I prefer to see it actually live in action when I start the game so now we know that the status code works and we're able to pull the number data out from it what about if we try to pull array data from our Json file so we know that in our Json file we have an array called Data so let's try to pull the array out of the Json file so pulling from Json object let go and type in try get array field like just like this and then field name will be the field name provided in the Jason file so again it'll be data I'll copy it contrl C back in engine I'll paste it and now you can see we have an out Json array so it provided us with an array so this array is providing us with every single entry given in this data array right here in the Json file so if I open this array up and as you can see all of these are specific objects even though they don't have a name all of these are objects which contain specific data about one individual character in valerant so when you're in Unreal Engine and you receive this out Json array you are actually referencing every single one of these individual objects which contains even more data within itself how would we go about pulling specific data out of each array field so now that we have loaded the array into engine and we can access each individual uh entry in the array let's try to pull the name of each valer character and print it onto the screen so what we're going to do here is for each Loop which will Loop over this whole array and we're going to try to retrieve a new data field called display name so this field entry here field name is called display name which will pull the name of the valerant character which in this case Gecko and then if we move if we collapse this object field and open up the next object field this one is called fade and if we do that again deadlock and if we move down a little bit silver so it should retrieve every single name of each character in valerant so pulling from for each Loop let's do a new node called try get string field like that and then provide the field name of display name and then let's just connect that with print string and change the display duration to maybe like 10 seconds and then let's test it out so now in theory we should be able to see every single valerant character's name as a debug message right there jet Omen Raina Sage yoru neon ISO Brimstone etc etc as you can see it it worked it went through the whole Json file and pulled each display name from each object within an array and provided it me as a print string okay so this was quite a simple um example of just pulling a string field out of a an array of data and printing it on the screen but what if a Json file is more complicated and has nested arrays within an already existing array as you can see the data field is an array and within this uh object we have abilities which actually is another array field as you can see and when within this array field we have every single ability for this individual character so how would we access this uh field well very simple instead of using try get string again we would just do try get array field like this and then just provide it with the array field name which is called abilities and then once again just run a for each Loop to pull the data out of this array field in the Json file so let's now try to get the display name of each ability so it'll be a string again so try get string field and then the field name and then print string print it to screen and just make the duration longer and now we will print every single ability for every single character in valerant let's test it out as you can see all of the skills which can be found for each champion in valerant are right here as a debug message so up to this point we have used the try get array field try get string field and try get number field field we also have a bull field and an object field they work exactly the same as the ones we've just used so I'm not going to Showcase how these work but they follow the same principle you just provide a field name and then the data associated with that field name will be given back to you the only difference is try get all object field names how this will work is it will take the provided Json file you input into it and retrieve every single field name which you can see here to you in an array then you can Loop through each array each entry in that array and retrieve every single field name this is useful if for example you want to automate something where you don't want to have to go through the Json file and look for a specific name so you can just use this to retrieve all the field names and then find the field name you're looking for that way I'm not going to Showcase how this node works right now because it's very self-explanatory but in the future if people want me to do a video about it I will do a separate video showcasing how this node works but for now that's going to be everything for all of the tri get nodes which allow you to get data out of Json files now the last thing I want to demonstrate is actually how to remove Json fields from a Json file so what we can do is let's take that already loaded in Json file we have with all of the valorant characters and let's say we want to remove a field let's say we want to remove the field character tags and the background gradient colors how would we go about doing that so we already have a four each Loop here which Loops over every single object in the Json file let connected to remove Json field and then provide it with a field name we want to remove so in this case we want to remove background gradient Colors Let's copy the remove Json field again connect it to the out the new Json object and then also let's remove character tags like that that's everything we have to do these two nodes now will remove those fields from each object found in the array if an object doesn't exist it will this will fail and just continue what I recommend is using the success node out here so you you will know if it successfully removed a field or not but just for the Showcase I don't have to CU I I know 100% that it will remove these two Fields I'm going to let it Loop over the whole array removing these fields and once it completes right here I'm going to take the loaded file again and I'm going to save it back to disk so I'm going to do is do two string like this and then save file to disk make a new file data provided with project directory and give it a new name so the name is going to be new Json data. Json so what I'm doing here is converting the already existing Json file to string and saving it to disk I've covered how to do this in the first tutorial so if you're not sure how to do this please go watch the first tutorial and you'll you'll know so now if I head back into the game and start it like this and see nothing happened but now if I close the game go to my project files in the project files you'll find a new Json file called new Json data if I open this up as you can see we no longer have the two Json fields we had before which were character tags and background grading colors for every single object in this Json file they all have been removed so that's going to be about everything for this episode showcasing how to load Json files into an real engine and how to retrieve data from loaded files in the next episode I'm going to cover how to send HTTP requests to different AP I and how to read the data received from a API request till then see you
Info
Channel: Unreal Center
Views: 1,093
Rating: undefined out of 5
Keywords: Unreal engine, UE5, UE4, JSON, HTTP, Tutorial, Utility, Unreal marketplace, Marketplace, Playlist, Unreal engine 4, Unreal engine 5, How-to, How to, Step-by-step, Walk-Through, Tutorials, Two, Json file, Json loading, json reading, Json custom data, Unreal, Center, Unreal Center, How To JSON in Unreal, How to JSON in Unreal Blueprints
Id: l0gokKjzH6s
Channel Id: undefined
Length: 18min 8sec (1088 seconds)
Published: Sun Jan 14 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.