Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Collection content gets lost on build #76898

Open
CookieBadger opened this issue May 10, 2023 · 0 comments
Open

C# Collection content gets lost on build #76898

CookieBadger opened this issue May 10, 2023 · 0 comments

Comments

@CookieBadger
Copy link
Contributor

CookieBadger commented May 10, 2023

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

  • 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:
CSharpDataDisappears

Minimal reproduction project

CSharpCollectionDataLoss.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants