-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Mono: Base class members reset to their default values if derived class has [Tool] #37812
Comments
I'm having the same problem but I didn't make an issue because I couldn't reproduce it reliably. It's super annoying now because I've converted a lot of scripts to C# and it's resetting (seemingly) random sets of nodes in my scenes. For instance, if I have a wall, a couch, a vending machine, and a sink, it will sometimes decide to reset just the walls and the couch but not the others. They all derive from the same classes and all use the [Tool] functionality. Hope this gets looked at! |
@Pahasz Do you think you are now able to reproduce the issue by following my instructions? |
@Phischermen Yes I was able to reproduce it in the reproduction project using those exact steps. |
Same here and it is super annoying. Cannot really use the Godot editor to build test levels anymore as I could when my game was still written in GDScript. Btw. the bug is cross plattform as I am running Linux. |
Any update on this? |
Also interested in the solution of this issue. |
There is this post in the Godot Devblog. It seems that after Ignacio organizes the Godot API into namespaces and provides a .NET friendly IO API for the Godot virtual file system, he will dedicate a month to bug fixing |
this is also happening on 3.2.2.stable.mono |
It's been happening from 3.2.1 through 3.2.3 beta-1 for me. |
Happens on 3.2.3.stable.mono |
Still happens on 3.3 RC 6. Tested with the sample project to confirm. |
Still happening on v3.4.stable.mono. This heavily discourages the use of |
Also seeing this here with 3.4 stable and 3.4.1 RC2. My observations, maybe they help:
When can we expect #53975 to land on 3.4, as this - as I interpret it - addresses the problem? |
I don't think #53975 fixes this issue, that PR was made to fix an issue that only affected |
Thank you @raulsntos! What’s the timeline for 3.5 and do you have a workaround for the meantime, even if it means changing some code? |
There is no ETA for Godot releases, but since 3.4 was recently released, I expect 3.5 to be released in about 5 months from now. |
You can workaround it by closing the scene before building, as described by Scripptor: #37812 (comment) |
The current workaround I've been using is to convert the C# Resources to GDScript and create a C# wrapper for them. Example of a Resource wrapper class//The wrapper class of a resource
public class MyResourceWrapper {
private Resource resource;
public Resource Resource {
get => resource;
set => resource = value;
}
public MyResourceWrapper (Resource resource) {
Resource = resource;
}
public static MyResourceWrapper LoadResource(string filePath) {
return new MyResourceWrapper (ResourceLoader.Load<Resource>(filePath));
}
public string MyProperty1 {
get => (string) Resource.Get("MyProperty1");
set => Resource.Set("MyProperty1", value);
}
public int MyProperty2 {
get => (int) Resource.Get("MyProperty2");
set => Resource.Set("MyProperty2", value);
}
} PS. In practice I have the Resource field/property and constructor delegated to an abstract class. When needing to use a Resource in a class I export a Resource property and use the get/set to handle the correct conversion/wrapping. (Perhaps not the the cleanest, the set/get functionality could also be delegated to the constructor but you get the idea). Example of a class that uses a Resource //Class that uses a Resource
[Export]
public Resource MyResource {
get => myResource?.Resource;
set {
myResource = value switch {
null => null,
MyResourceWrapper resource => resource,
_ => new MyResourceWrapper(value)
};
}
}
private MyResourceWrapper myResource; This main advantage from this solution is that it allows me to use the ResourceWrappers like they are real C# Resources and keeps refactoring of my code minimal. This also futureproofs for when the fix releases, as all I need to do is switch the GDScript resources back to C#, and use those instead of the wrapper. |
What replacing all properties with class member variables also work? Or would they be reset randomly, just as well? Also, can we vote to get a 3.4.2 and include the fix there? The workarounds are not really options IMHO and waiting months for 3.5 isn't a pretty alternative :-( |
Since #53942 doesn't break compatibility with existing projects, it should be safe to cherry-pick to In the meantime, you could build a Mono-enabled editor and export templates from source with #53942 included. |
I have struggled a lot in the past with this problem, I'm glad that this error will be fixed in the next version. I suggest you a safe solution, it was always worked for me. Define your main variable as a virtual variable in base class and re-define your variable as override . Example; Base class;
Re-define your variable in the derrived class; When we define the variable in this way with "override", it treats its as a special variable that is not specific to the base class. So we're fooling Godot. |
Built custom Mono Godot Editor which fixes Issue godotengine/godot#37812 that previously required use of the ResourceWrapper class to fix. Version: 3.4.2-stable Added Commit: godotengine/godot@907e709 Related Pull Request: godotengine/godot#56300
Godot version:
3.2.1.stable.mono
OS/device including version:
Windows 10
Issue description:
C# base class members reset themselves to their default values every time the project is built if the derived class has the [Tool] attribute. I have not been able to reproduce the issue in gdscript.
Steps to reproduce:
Minimal reproduction project:
DerivedC#BugTest.zip
The text was updated successfully, but these errors were encountered: