You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you rebuild after changing some C# code in mono Godot, and you have some other (unchanged) C# code running in the editor, such as an EditorPlugin, any data that was stored in C# collections is lost.
From my understanding Godot serializes all information during before the rebuild, strips all scripts from the objects, then reapplies them and deserializes the saved data. Thus, if your objects currently store any kind of data that Godot can't serialize (C# collections, custom classes that don't inherit from Godot classes, anonymous functions, or basically anything that's not compatible with a Variant), that data is lost on rebuild.
My best guess is, that this is not a bug, but related to #70298. However, the intransparent processes during the build of C# code ("Unloading assembly load context... Copying Godot Offline Packages...") made this realization quite difficult to make. I still wanted to post this, in case it is indeed a bug, or in case it saves somebody's sanity -> the workaround is to use Godot collections for object states, and having any custom data objects extend from something Variant compatible, like GodotObject.
Steps to reproduce
Have a C# EditorPlugin with some System.Collections.Generic collection with some data running.
Change something in any script file
click rebuild
observe that the data inside the collection was lost
You can use the reproduction project to do so, observing the output:
Godot version
4.0.2 mono
System information
Windows 10
Issue description
When you rebuild after changing some C# code in mono Godot, and you have some other (unchanged) C# code running in the editor, such as an EditorPlugin, any data that was stored in C# collections is lost.
From my understanding Godot serializes all information during before the rebuild, strips all scripts from the objects, then reapplies them and deserializes the saved data. Thus, if your objects currently store any kind of data that Godot can't serialize (C# collections, custom classes that don't inherit from Godot classes, anonymous functions, or basically anything that's not compatible with a Variant), that data is lost on rebuild.
My best guess is, that this is not a bug, but related to #70298. However, the intransparent processes during the build of C# code ("Unloading assembly load context... Copying Godot Offline Packages...") made this realization quite difficult to make. I still wanted to post this, in case it is indeed a bug, or in case it saves somebody's sanity -> the workaround is to use Godot collections for object states, and having any custom data objects extend from something Variant compatible, like GodotObject.
Steps to reproduce
You can use the reproduction project to do so, observing the output:

Minimal reproduction project
CSharpCollectionDataLoss.zip
The text was updated successfully, but these errors were encountered: