Edit a structure causes data loss

Hi,
I create a structure S_MyStruct (string, integer)
I create a scene component, with no code, only one public variable “MyVar” of type S_MyStruct
I create a BluePrint Actor “BP_MyActor” with the scene component. In this BP actor I add a test code : custom event and I change a value in the scene component variable MyVar.

I place a BP_MyActor in the level and edit the values of S_MyStruc in the details panel.

Now, I add or remove a field in the structure. The BP_Actor must be recompiled. The issue : The values in the instance of BP_Actor in the level are resetted.

The game is not launched, the code is not executed. It’s only an editor issue.

If I quit Unreal before recompile BP_Actor and restart unreal, no data is lost !! but it’s easy to forget and all my game data will be lost if I forget.

Is it normal or is it a bug ? Have you a workaround, what can I use in place of structures ? (Blueprint only)

PS : Unreal often crash when I edit a struct or struct variables…

Thank you :slight_smile:

Hello @olivier03
If you change the structure that you are already using in blueprints, it will naturally reset all the values and every blueprint using this structure will need to be re-compiled. Generally I would suggest you avoid changing existing structure. As you can tell, this can cause all sorts of problems. Best to plan ahead or create a new structure altogether. Structures in blueprints can really be a pain at times, it’s a well known fact.
Perhaps using something else, like data assets can better fit your needs. Should also help you with preserving data.

Data Asset doc

Thank you for your answer.

I’ve tested without the component. I put “MyVar” in “BP_MyActor”.
When I add or remove a field in the structure, I recompile the actor but this time the data in the instances (details panel in the editor) are not lost !
I will rework/redesign my code to do like this.
I will dig into the data asset too.