Unreal Engine 5 Tutorial - Data Assets

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] foreign to this video that was voted for by my patreon members so thank you for everyone who voted for data Assets in this episode we're going to go through and explain how data assets are used why you may want to use them and what are the benefits and differences of using them compared to data tables so let's get started okay so let's talk about data assets so the whole purpose of a data asset is a way of storing information now you may already be familiar with using data tables and data assets are just another way of storing data just like data tables already stored data too so let's take for example our data table set up we have a structure which defines this resource with a name description and mesh exercise and cell value and we made a data table with those values in there or flower Crystal and iron ingot and mushroom with various information in there now you'd have in here all the items in your game okay defined here just read only data table now the issue with that data tables are is that they are um can be quite cumbersome um because they can get very very large and if they are very very large you run into an issue where the data table takes longer longer to go through because it has so many rows whenever you are doing a fine data table row what it's doing is going through each row sequentially to find the right one now what may actually be better and easier is if you have each row of this as its own asset that's essentially what a data a data asset is so let's go for the process of creating a data asset so I'm going to go over to our I'll just here I'll just make a new folder keep this a bit tighter and in here we'll have in here a pretty big class and you go to all classes and search for primary data asset click that and we'll name it we'll go um resource data asset and in here you give it variables much like how we gave it that structure for the data table so in here we're going to have the name which is a text field we have a description we'll also have in here mesh it's going to use mesh and do static mesh what now um we have a stack size which is a integer aim that one and we have a cell cost that'll be afloat okay so you're putting all the variables you have in here like so but as you can see you can have other things in it so not just uh you uh as just like a data table which has just data on it a data asset can also have functions and event dispatchers on there too so you can actually put Logic on there to run on the data asset so this can be very useful if you wanted to do calculations for example um like in other words what we do here this cell cost is we'll go to functions we'll make a new one to get um new uh it looks a new discounted sell cost and that could give us a input for a float and that'd be the percentage of it so um we'll do a factor and the output for that would be the new value new cell cost and we just simply take that factor there and multiply that by this so cost Okay so we've got this function here that we can easily get hold of not just the cell cost but also add a multiplier to it so if you want to get a 10 discount just multiply by 0.9 so more or less than a second when we go into it I'll show you how to hold it up but just so you know you can do things like this in fact we'll make this a pure function whilst we're here okay so that is how you define a data asset let's actually make one though just right click in here again and go to miscellaneous and choose data asset in the drop down It'll ask you to pick uh the one you want to use we're going to use the resource data asset so let's find that there it is and now we can create our date of assets so in here we're going to have a flower and open it up and you just put in the information you want to have a flower is yellow flower has been said to have healing properties I would give it the mesh so we'll create that one stack size we'll do 99 sell cost to do 5.5 right right and if I want to make another one I just do the exact same method again you create another one so you go to here miscellaneous date of asset and so on however you may find that a bit tedious after a while so what you can do is just right click on your file here duplicate it and then you can do the next one we'll do mushroom for example and in there we can choose the mushroom we want to use go back here mushroom mushroom and that'll be this fungi is right in a soup and you can change the upper values obviously to whatever you like and you just keep going on and on and on now another really useful thing about data assets is that because they are single assets here um which makes them better for memory but also it helps you just organize yourself a little bit better so rather than having a long list inside a data table which you can search obviously you can actually just put in folders here another organization methods to help you store locate and um reuse your data assets throughout your project so let's say I've done all of my data assets and I really don't want to use it in the game so let's make a little actor that I pick up to give me that asset so I'll go over here create a new blueprint class new actor and that be item and we can go in here and say give this a mesh so and then go to the verbals down here and give it a data asset so just click data and in the drop down or search my resource data asset now when I compile that I can choose which one this is going to be over here so let's say for example I make this one editable and on the construction script I'll drag out my data available convert it to a validated get so if it hasn't been set it won't do anything but when it gets the data I'm going to drag out and search for mesh it's just like looking for another variable on any other actor so do get mesh and now I can set that now to my aesthetic mesh component so set mesh so I'll save so now if I dragging this item into the world so there I can click on a data asset option here choose flower and it'll put in a flower change the mushroom it'd be a mushroom okay and if we're going to play a character you're doing a inventory of sorts it works exactly the same as if you're storing row names for a data table right so row names you store data assets so you made me familiar with a variable type such as this for inventory we have inventory set to a name and a map finish just so you know how many your items you've got of each one rather than using name just change it to your resource data asset pile and save so when I want to add an item to inventory just dragging that out there and doing add and you just choosing the data asset from the drop down or plugging it in and the quantity and much like how you do a row name or anything else so it's very very similar in that regard and it is similar in a sense that it is read only so you can't change any data inside of a data asset you can only read from it but as mentioned earlier you can do certain things with it so for example if my player character wants to sell um something so do a function here called sell item and in here we're going to go to the variables and set to resource data asset item I don't want to sell the item I could drag this out and I get the sell cost so to sell cost and you'll see get discounted sell cost this is the function we made earlier so I can call the function on my data asset give it a factor here of saying 0.9 and give myself a 10 discount so I can sell that and now do the logic here to actually get that money out onto my character but there you go data assets are really cool useful tools especially because of those functions you can do but do try them out and I I've been using a lot more lately and been enjoying my time with them so there you have it data assets are a wonderful tool that's been added to Unreal Engine and I strongly recommend trying them out they're good fun and very much a nice easy way to manage large amounts of data now if you want to vote for other videos head over to patreon.com forward slash Ryan Bailey where you can become a silver team member and start voting for next month's videos right now thank you so much to our patreon members for the content support and I'll see you all next time bye everyone thank you [Music] [Music] foreign [Music]
Info
Channel: Ryan Laley
Views: 48,920
Rating: undefined out of 5
Keywords:
Id: Pb0uhYoUmb8
Channel Id: undefined
Length: 11min 13sec (673 seconds)
Published: Mon Feb 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.