Hello! I have recently been looking at sample projects from Epic Games to learn how to properly code games and I’m a bit confused. I noticed that all of the projects are using data tables and data assets and I just couldn’t wrap my head around of benefits of using them.
Let’s say I’m creating an RPG and I have some items in the game, usually what I would do before is I would create a base class Item in C++ with basic things that this item needs like static mesh, some effect, etc, and then game designers would just simply inherit from this class to create items like Chair, Door, etc and would set up properties in details panels.
But apparently more proper approach (if I understood correctly) would be to create a basic C++ class for the item, create a base blueprint class for the item, and then create a primary data asset for the properties of this item and let game designers create data assets for these items and put them in the base blueprints.
But why would I choose the second approach over the first? The only reasons I have come up with are that data assets are allowing to be more modular. So basically one blueprint could have multiple data assets within it and if some designer is changing one data asset they don’t need to worry about merging changes with other people who may work with other parts of this blueprint.
So could someone please explain how and when to properly use data tables/assets and why they are useful? Or at lease give a link to a resource where I could learn about it.
I never used data assets and maybe someone else can explain some benefits of that.
Yes this is most common. Especially with widgets I write all logic in c++, declare any Slate widgets the c++ class depends on in c++, let designers create a Blueprint inheriting from it purely for design purposes. It separates the programming of pure functionality from the design process which can be good. In practice the blueprint thing could be skipped for most other things.
Often you should be asking yourself “am I making a new class, or just a variant of one?”. A variant should not be turned into a class. To create a variant you should use injection of data, which is where datatables come in handy. Datatables are a way of centralizing your data management so that changes can be made in one place and saved in a single file. Additionally they can be exported to excel so tasks like increasing the price of all your ingame RPG items by 10% could be a simple excel operation.
Using a new class instead of a datatable can be done when you need new functionality and not just data for existing functionality. You could create a bird that can fly and a dog that can run from the base class animal. It could be a different implementation of a combination of functionality as well using component classes, programming your run and flight behavior into component classes, then added to a new animal class.
using datatables you can provide or swap a large set of data to any class without the need for additional classes. It doesn’t provide functionality but data. Think of swapping out the textures for gamepad keys to keyboard keys when you swap input devices. Think of providing centralized data like how much damage every enemy in the game does on different difficulty settings.
Personally I try to stay away from blueprints and UAsset classes for as long as possible since they are more difficult to read and manage than plain text files like cpp. For widgets, animations, sounds etc you are going to let the visual or audio designer work with blueprints anyway because they need to work with the editor windows. It’s a bloated extra step because UE only works with uassets. It basically copies the source file + editor settings + writes editor data like the pins and nodes you create, instead of just referencing a source file. At least with datatables you can modify those as json or csv.
It is all about how do you store “default” values for game. Yes you can put all those numbers, strings etc in each blueprint that needs it. But where you put values that multiple bluepritns/actors need? Data assets are awesome, you can code stuff in their constructor, and still have data asset.
Also one warning about data assets (and hopefully somebody knows why this happens).
I used data assets in my project however sometimes some assets are not loaded properly. This can cause random crashes that are quite hard to replicate and track back.
So if anybody knows why this happens and how to avoid it. I seen asset manager in lyra (not checked it really, as i moved from data assets).
Data tables are lists of items while classes and data assets are individual items.
If you have a lot of simple items, it may be more simple to have them as table entries and use one dynamic class. If you don’t ever query a list then I think it’s how you prefer working with the data. Needs vary.