Godot: [Mono] Loading a scene with unbuilt/unexported variables automatically erases them.

Created on 5 Jan 2018  路  8Comments  路  Source: godotengine/godot

Godot version:

34c988cfa92f19c232b65990704816ba1c7d2622

OS/device including version:

Any

Issue description:

Any variables in the main scene or any scene that gets opened before the Mono assembly is built will be automatically erased.

The most practical solution seems to be to build the mono assembly immediately upon opening the project prior to any scene opening. This way, any changes from other team mates that have been pulled in will also have their variables intact instead of erased

Steps to reproduce:

1) Clone the following project
2) Open the project
3) Select the BehaviorTree node (notice no exported variables exist)
4) Build the project with F5/F6 (and then hit F8 to stop)
5) Quit the editor
6) Open the project again
7) Click on the BehaviorTree node
8) Notice "Navigator Path" is empty
9) Quit the project
10) Do a "git reset --hard" on the repo to reset any changes
11) Open the project
12) Notice "Navigator Path" now has its correctly saved value

Minimal reproduction project:

The following project is the same one used in the video

Project:
https://github.com/NathanWarden/godot_ai_csharp

Video:
https://youtu.be/ymvryIPuZRU

bug mono

Most helpful comment

Update: This issue is still valid. It was a special case which made me unable to reproduce it. Interestingly, thanks to this I started to understand the cause.

I think I came up with a good solution and I made a basic implementation for C# scripts. So far it seems to be working, but I haven't tested much.
The solution is to backup the exported properties when updating them. If a scripts fails to compile, instead of updating the exporting properties the normal way, it loads them from the backup file. Here is a wip: https://github.com/neikeq/godot/commit/c597db03955f90a8c163e8e1ae23ada8253ea9c7
It's just a quick draft I made to confirm it works. Ideally, I would prefer this to be done by the editor, instead of being hard-coded in languages.
My implementation doesn't deal with tool scripts for now. Reason: they cannot be instanced if compilation failed, and they don't use placeholder script instances...

Another important fact to keep in mind is that this issue may not only affect properties, as it seems to be the case with #17070.

Anyway, I would really like to hear opinions. Specially @reduz

Reminder: this issue affects all script languages, not only C#.

All 8 comments

Not only building it before opening the scene sounds like a hacky workaround, but if building fails then you still lose the variables.
It's weird though, because AFAIK you don't lose those variables if a GDScript fails to build, right? Maybe I'm doing something wrong.

It's weird though, because AFAIK you don't lose those variables if a GDScript fails to build, right? Maybe I'm doing something wrong.

Oh, wait. Actually the same happens with GDScript. Implementing automatic building should solve this issue then (supposing build doesn't fail), but IMO losing changes on exported variables when a build fails is really bad...

Yeah, I am using export variables a lot with tool scripts, and if I make an error, they are gone until I fix it. I wish it didn't happen...

So, maybe Godot itself should just keep the variables until there's a successful build? This should cover all cases in all languages.. maybe?

I think yes, and instead of the reset-to-default button show a warning icon or something.

Look what I found: #17070

I cannot longer reproduce this on latest master. @NathanWarden can you still reproduce this?

Update: This issue is still valid. It was a special case which made me unable to reproduce it. Interestingly, thanks to this I started to understand the cause.

I think I came up with a good solution and I made a basic implementation for C# scripts. So far it seems to be working, but I haven't tested much.
The solution is to backup the exported properties when updating them. If a scripts fails to compile, instead of updating the exporting properties the normal way, it loads them from the backup file. Here is a wip: https://github.com/neikeq/godot/commit/c597db03955f90a8c163e8e1ae23ada8253ea9c7
It's just a quick draft I made to confirm it works. Ideally, I would prefer this to be done by the editor, instead of being hard-coded in languages.
My implementation doesn't deal with tool scripts for now. Reason: they cannot be instanced if compilation failed, and they don't use placeholder script instances...

Another important fact to keep in mind is that this issue may not only affect properties, as it seems to be the case with #17070.

Anyway, I would really like to hear opinions. Specially @reduz

Reminder: this issue affects all script languages, not only C#.

Was this page helpful?
0 / 5 - 0 ratings