Server & coding

Data Assets (vs Data Table)



Traditionally if using Data table

(if many assets, gonna create many rows resulting in heavy load)

Create a Structure (name as F Rerouce), and a data table (, choose FRrsource as a structure give to data table, name as Resources_DT)
Input wanted data in:
image.png
image.png

If using Data Asset, create a BP class as a Strcuture):

Create a folder called DataAsset
In BP class, type Primary DataAsset
image.png
Create and name as ResourceDataAsset
Add variables that are equivalent to Structure command
(Use DataAsset advantage over Strutcure: can also add Functions and Event Dispatcher)
image.png
e.g. Create a new function to Set a Discount New Sell cost by BP:
image.png
Tick Pure in Functions Detail

Create DataAsset to connect to Primary Data Asset:

Now R click and go to Miscellaneous → Data Assets
image.png
Choose ResourceDataAsset just created
e.g Name as Flower (as 1 of the asset)
Fill in follow info
image.png
Duplicate the Asset and rename it (e.g. mushroom), open the asset and change its mesh, name, description, etc

Create a BP actor called Item, add a static mesh component
Add a variable called Data, choose Resource Data Asset
image.png
After complie, can choose the asset in default value:
image.png
Tick box Instance Editable, Go to construction script, set as follow:
image.png

Drag the Actor in scene, choose the asset in Default Data
image.png


Optional (not fully undetstood)
If to make a character doing inventory resource:
Open 1st/3rd person BP, add an inventory variable and select follow variable Types:
image.png

Make the follow graph, choose assets from the Add node (it’s read only, can’t change any data inside data asset)
image.png

But can set the player do some functions, e.g. Sell items
Create a new function called Sell Item, add Item in input, then drag the node to connect Get Discounted Sell cost function (created earlier on)
image.png
image.png
Set the factor as 0.9 (i.e. 10% off), then extend the node logic to let character gives money out


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.