How to reset a PrimaryDataAsset when testing in the editor?

After learning that data structures cannot use generalization or inheritance, I searched for an alternate way to create data that allows me to use some kind of generalization. After some time, I stumbled upon the blueprint class PrimaryDataAsset and this appears to be exactly what I am looking for, being very similar to ScriptableObject in Unity.

However, when doing some tests, I noticed that blueprints which inherit from PrimaryDataAsset keep changes even after exiting play mode in the editor. Let’s say there is a boolean variable in my PrimaryDataAsset which I change at runtime, then it will keep that new value when exiting play mode.

While this is actually neat because it allows to keep data, it is also kind of a problem because for instance when testing your stuff, you do not want to have changes from your tests remain after exiting testing. Additionally, when creating games with saves, how would you roll back a PrimaryDataAsset, let’s say if you saved your quests flags there and the player reloads a save file from before, when some flags weren’t set.

Is there an easy way to solve this or do I not use PrimaryDataAssets correctly?

did you ever figured this out?

DataAssets are never loaded in as instances, you only have access to their in-memory representation of the file itself as a CDOs (Class Default Object). Data Assets should be considered Read Only at runtime and not modified.

You might want to make a normal Blueprint Class just extending UObject instead of a DataAsset and create an instance of it at runtime, then you can change it to your heart’s content without it affecting the source asset itself like is happening in your case.

1 Like

This makes sense. But why it doesn’t reset the data after closing the Play in Editor to simulate how a real game behaves? Anyway, I’m now getting the data from the asset and save it in different variables so the game doesn’t access or change the asset data directly

The editor doesn’t load everything twice when entering PIE so it keeps assets in memory like meshes, textures and CDOs. You’re not supposed to change CDOs, if you do you’re basically changing the in-memory representation of the file which the editor tries its best to not reload unnecessarily. Not reloading them should be fine since CDO’s are not supposed nor expected to be changed during game’s runtime.

1 Like

I’ve switched to loading the data asset and then assign the values to something else inside the game. Now the data assets remain as they are and it is not important if they are loaded in memory or not, I mean, there is no need to reset them back

1 Like