![]() |
Data Shard Plugin
|
Now you have created a key pointing to the new shard. This key now points to a float shard where the value from 'Player Init Health' is entered.
In this example, we retrieve the data before setting it. For this, we use the previously saved 'Player Health Key' variable, where the key was stored.
After calculating the correct value, we call 'Set Shard Data' and assign the new value to the 'In Data' input.
Binding is one of the core features of this plugin. We get a new key, which provides access to an existing shard. To do this, we need:
With the 'Create Bound Key' node, we create a new key that has access to the same shard as the 'parent'.
Now we can access the same shard data with both keys at any time, without needing additional data forwarding.
You can add events that will be executed when specific shard data changes.
In this example, we modify the 'Create Shard' part by adding the 'Bind Event on Shard Data Change' node. We use the same key that was used to create the shard. Now, every time the shard data changes, the 'On Shard Data Changed' event will be triggered, which will then call the 'Update Player UI Health' function.
Most of the functions we need are located inside the DataShardSubsystem
The DataShardSubsystem::CreateShard function has two overloads. The version that includes a Container and PropertyName is more user-friendly.
Key
, you can directly use the uniform initialization {Owner, "Name"}
in the function.or
RETURN
macros return you a pointer.
GET
macros create for you the pointer variable
There are also other macros that may be useful. Take a look at Helper Macros.
COPY
macros.Currently, there is no way around using members to create and set the shard data. We use the Unreal Reflection System (FProperty), which are created by the UHT (Unreal Header Tool) at compile time. For more complex or nested data types, such as structs that contain other structs, it is too complex to build them at runtime.
You can create global keys, which means there is no owner. They work the same way as normal keys, but you can use them anywhere, and they are not bound to a specific owner.
const FDataShardKey GlobalKey = {"Global Float Key"};
To set self in a shard you need to cast the self node or create a variable. Otherwise you will get an error.
Command | Function | Description |
---|---|---|
DumpAllShards | DataShardSubsystem::GetShardDump | Use this command to get all shards displayed in the output log |
DumpAllKeys | DataShardSubsystem::GetKeyDump | Use this command to get all keys displayed in the output log |
DumpAllReferences | DataShardSubsystem::GetRefDump | Use this command to get all references displayed in the output log |
DumpAllShardsString | DataShardSubsystem::GetShardStringDump | Use this command to get all shards displayed in the output log |
DumpShardPoolSize | DataShardSubsystem::GetPoolSize | Use this command to get shard pool size displayed in the output log |
DumpShardPoolActiveAmount | DataShardSubsystem::GetActiveShardCount | Use this command to get shard pool active amount displayed in the output log |
DumpShardPoolAvailableAmount | DataShardSubsystem::GetAvailableShardCount | Use this command to get shard pool available amount displayed in the output log |
You can use the built-in Unreal Engine Visual Logger. I recommend taking a look at the Unreal Engine Documentation
Under Tools → Debug → DataShard Debug, you can find the Data Shard Debugger. This tool allows you to view all keys, shards, and the data inside the shards.
You can double-click on the owner nodes (on the left side) to jump to the actor.
When selecting a shard node, you can see the data inside in the Details panel.
With the 'Pause' button at the top left, you can pause changes. This will freeze the debugger, allowing you to inspect everything for as long as you need.
You can filter by Actors (Key Owners). You can select one or multiple actors. When selecting one or more actors, only the affected shards, keys, and actors will be shown.
By default, the debugger doesn't clear when you end the PIE session. You can enable this by checking the 'Clear on PIE End' checkbox in the top right.
You can move the nodes as you like. If you want to reset their location, you can click the 'Refresh' button.