Help understanding Data Assets

I made a Primary Data Asset for the weapons in my game and gave the primary data asset some functions to handle ammo.

I made a pistol asset and when testing it at runtime the functions are changing the value of the pistol asset class not an instance of the pistol asset.

So when I close PIE the pistol asset’s current ammo value has changed to 0 when it’s supposed to be 17.

Am I using Data Assets correctly? I had intended to use Data Assets for the weapons in my game and track the amount of ammo they had within the data asset.

Should I be creating an Actor instead and just using the data asset to fill in the static values (magazine size, mesh, name, etc) while the actor handles the dynamic values like current ammo and stored ammo?

1 Like

The data assets are great for presets, and actors are fine during runtime, but if you want to remember values between game runs, then you need to put them in the save game.

So data assets are just for preset data? you’re not supposed to change the values in them during runtime?

I’m guessing then that the best way forward will be to have a Weapon Actor, put the Data Asset values into the actor and then let the actor itself do all the manipulating of values since the actor can be instanced?

1 Like

If you could write to data assets at runtime, you would be writing to the asset manager.

I’m not sure if that’s possible without changing source code? ( I freely admit knowing very little about data assets ).

Also, how would that work in an installed game? Can the player write to the program install directory during runtime. The user profile is the typical place to write things like this, which is what the save game does.

Even if you use an actor to create an asset instance, you still need the save game to avoid losing data after runtime.

That’s interesting!

I might be mixing my terminology a little bit. by runtime I mean the play in editor mode to test the game. When I play in editor and run the script to shoot the gun it calls functions in the Primary Data Asset to reduce the current ammo in the gun.

Now before I run PIE the Pistols data asset shows 17 Current Ammo, if I hit play and shoot the gun a few times then exit, the data asset in the content browser shows current ammo as missing the ammo that was fired.

This has confused me as I thought the Data Asset would be an instance and not change the default value of the Asset in the content browser.

This is the first time I’m using Data Assets after seeing a tutorial on them, so I’m probably misunderstanding how they’re supposed to work.

Ok, interesting… :thinking:

Apparently, it does change the asset, but then you have save the project. Doesn’t really sound like a viable route forward to me :rofl:

1 Like