Unreal Engine Data Assets EXPLAINED

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in some Paul's videos I've talked about structures and data tables as a way to store and read data in a very efficient and useful way today we're going to talk about a different way to do something very similar and that is with data assets the way you can think of data assets are just slightly more flexible individual entries of a data table so where we have data tables being one single asset with a bunch of entries in it a data asset would just be one of these entries as a asset in and of themselves the difference being is that a data table is read only and a data asset you can actually write information to or maybe it's just easier for organizational purposes to have them as individual assets like in my case so let's go over the basics of how to set up a data asset and how to create them and then I'll come back into my own project here to show you some of the implement patients how it works in my own game creating a data asset is actually not that difficult what we can do is simply make a blueprint class and make one of type primary data assets and we'll call this something like item data assets then when we opened it up we see a normal blueprint editor and there's two things you can do for a data asset the most important one is adding variables so for a item as I've been using for the example for the past couple of videos if you haven't seen those videos don't worry about it um we of course want a texture we'll want an item id we'll want a value we'll want a name and we'll want a description and give them all the proper types that come with that and now we have our template for our data asset so after we've done that we can come in to miscellaneous here and create a data asset out of that so we can create a item data asset and let's make a sword so when we open that up we see all of the variables that we can fill in this order is going to look like bricks Item ID is going to be zero the value let's say it's worth 100 the name will be Iron Sword and the description will say it's Sharp but a week and of course we can make a bunch of duplicates of this and also make a shield and then also make a potion and so on and so forth and then if we make a blueprint class so let's just go with a normal actor and call this actor just pretend like this is the player we can make a variable here for the held item the item that's currently being held and that can be of the type item data assets and when we see here when we compile it the default value we get a drop down menu of only the assets that are items so we can give it a potion a shield or Resort and pulling that into our event graph we can get any of the data out of there so we can get the item ID or we can get the value just like you would with any other actor it's important to note though that we can set these values as well so we can set the value when you do this you might think oh we're just changing the value on the item that's being held at the moment that is not correct what you are doing when you are setting a value in a data assets variable so not setting the value of variable you're setting the value inside the asset itself meaning that meaning that if you have a hundred different actors all with a reference to this type of data asset in this case the sword and one of them changes the value of the sword the Assad itself gets changed so all the other references to it now also have that updated new value which can be a really powerful thing if you know that that is the case if you don't know that that's the case and you're using data assets for like your enemy health for instance I just as an example that would mean that if you hit one of the enemies on screen all of the enemies take damage that's of course not what you want so do be aware of where you can and cannot use this I want to show you one more thing though because you might have noticed that this data asset does a event graph here where if you're familiar with something like structs there isn't and there is a good reason for that because you can actually make events and functions on data data assets so let's make a function here and say get sell price because this float variable yeah for the value we probably would use that for when we buy something right when we go to a shop it would cost 100 coins but usually in games when you sell that item then to that same shop or a different shop it would sell for a lower price so we can make a function on the data asset itself for get sell price and there we can simply uh uh like get a return node and say that we get the price divided by two when we try to sell it so that would be half of the actual value and we can add that bin to our return node or Excel price and now we have a simple function on here which will calculate the sell price based on the value variable which we can get sell price for the held item gets a node with a return pin of the sale price and that is the real power of data assets is the fact that they can hold variables and you can use them for a bunch of different things but they can also hold functionality on them as well to manipulate that data and make some simple calculations you're not going to want to program an entire actor based in a data asset but it does save you quite a bit of headache being able to make simple functions like this so let's go back to my own projects and show you two ways that I am personally using data assets in two different ways the first way I am using data assets in my own game here is by leveraging them for my combat system and if you've seen my combat system tutorials you'll be more or less familiar with how this works I have a child act up here which is the sword and that sword has a array of attack data assets as well as a special attack for uh when it's attacking up and one for when it's attacking down and those attack data assets contain a animation override which is just the animation that should play in the attacking state for this specific attack the forward Force which is a little push forward towards the enemy that you're attacking just to make things feel a little more satisfying the damage that the weapon should do when executing this attack the knockback it should deliver the particle system on impact the camera Shake on impact the sound of the weapon slashing the sound when the weapon hits and the characters are making a grunting sound all on a burr attack basis are implementable here the exact implementation to see how all this information is then getting read and put into action is a little beyond the scope of this video because it's also done in C plus plus and on blueprint but you can probably imagine that when I have a reference to this attack data asset I can just pull all this information out of it and use it in all of my other programmed systems and this way if I want to make a second weapon and a third weapon which eventually I will do it's just easy for me as just putting different data assets on them and I have an entirely new combo matter of fact this system would even allow me to add data assets to a weapon on runtime so actively during gameplay changing up the combo that my character can do the other way I use these is in my game instance where I have an array of events not events like custom events or whatever I just call them events which are data assets which simply have a ball variable a yes or a no so realistically this is just a fancy ball array the reason I'm using data assets though is because it is a lot more design friendly to use data assets for what I use these for and these are pretty much just flagging whether or not certain events have happened so if you can read the text here the First Data asset here is in level zero two have I beaten the Combat tutorial anime yet because if I have and I come back to that level you shouldn't spawn in again so in that level blueprint I simply look up this data assets and check are you true or false if your false spawn in the tutorial if you're not false so if you're true don't spawn on the tutorial the same thing with range anime tutorials the save point tutorial the anime spawner tutorial and then I have a couple of keys which are items that you can pick up of course if you've picked them up once they shouldn't spawn again so this array just keeps track of what actions the player has already completed and which it hasn't and then I also have a simple event set here to change a specific item in that array to a specific value and I have a function that Returns the value of a specific item that you're giving so if I go into this other for instance which has a reference to the game instance already in the level blueprint we can just ignore all of the programming that's already in here we can use that reference that I have to get events has happened which gives me a drop down menu of all of the events that I have made all the data assets and just simply returns a true order false out of it and we can also set events happened which again allows me to select a data asset of that specific type and set whether or not it should be true or false I could have put this functionality on the data asset Itself by the way I want to point out in this case I opted not to because it's easier for me to just be able to do that through a reference to the game instance itself so that's a few ways that you can leverage data Assets in your own game and a couple of things that you do need to be aware of there are references to existing assets they are not instances of anything so if you change one of them all of the other references to it also immediately have that same change going on but you can store information in it and you can do some simple programming with that information such as the buy and seller price that I showed you or the two functions that I just showed you in my own game those could have been on the data assets themselves rather than through the game instance and a very big thank you to all of my patrons you can see them on screen right now if you want to help out supporting the channel there's a link Down Below in the description to the patreon page and a special thank you to Eleanor for supporting at the cave Digger tier on patreon
Info
Channel: The Game Dev Cave
Views: 3,284
Rating: undefined out of 5
Keywords: data asset, unreal data asset, data assets, unreal engine data asset, unreal engine, data, unreal tutorial, unreal engine tutorial, unreal engine data, the gamedevcave, gamedev, gamedev tutorial, unreal data asset tutorial, data asset tutorial
Id: GQyo3q31jTQ
Channel Id: undefined
Length: 11min 22sec (682 seconds)
Published: Wed Aug 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.