-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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# scripts get reset/cleared/reverted by godot in certain circumstances #50163
Comments
Confirming that it is also happening on my projects, I use the same godot version. |
After testing a bit further, the SourceCode property of the script resource in question becomes empty when this issue arises. So it seems the editor is actually persisting this empty SourceCode property into the file, while it shouldn't. |
Can you reproduce this in previous Godot versions such as 3.2.3? |
Yes (3.2.3), it seems to happen quite frequently when building, then saving all. |
It happens with you when moving files between folders. And do the deletes files. |
Still an issue in 3.3.4 |
Still occurs in 3.4.2 when moving a script in the editor. Steps to reproduce (I think reliably?? NOTE: Do not deviate! Do not set up any project stuff.)
It has taken a while to find that set of steps. It seems even a little deviation will make it not happen. This bug triggers in the most random ways... fun. Hopefully it's just one bug and not something that needs to be fixed in a dozen different locations. |
I encounter an equivalent problem by generate c# classes over my GdUnit3 c# TestSuite builder I do as save by using the script editor to save possible changes before extending an existing script My code works fine to generate the new scrip but the editor shows still the old content. After comment out the save action the script is "reload" correctly. So seams to be the save action is not syncronzed and is overlapping with external script changes. |
This is still happening in 4.0 To clarify, this will still happen even when not moving a file. |
This happened to me in 4.0 without even moving the file. I will try to reproduce it. |
I believe that it has something to do with "state." because when I close the engine and reopen it in another process, The bug does not happen anymore. |
Still happening on 4.1.1 .Net version I don't know how to make the issue START to happen, but once it happens, it is persistent and is 100% predictable. I am using Win10 22H2, C# with VSCode Here's how it happens:
So here's what I've gathered from this, and I have observed this pattern 100% of the time.
EDIT
|
I'm still getting this in 4.1 w/ Rider. I havent yet divined the cause of it, but its super frusturating. I havent moved any files. I dont really understand why saving in godot overwrites the file if I havent got it open in Godot. That seems like some sort of cache whackiness. I'd move to V Studio but I cant get that to work for the mac (It doesnt seem to understand the solution files. Visual Studio code opens fine, but the code completion seems less than desirable, and I rather do enjoy IntelliJs IDEs. edit: Damn, reading the comments, it isnt an IDE problem but a Godot problem. Can this bug be prioritized please, its a show stopper and its deeply frusturating to have a bug wipe your work out. |
It could be fixed if someone managed to reproduce the steps to trigger this bug. In the past, I have tried to locate it, but it only occurs under certain conditions. Due to this instability, no one knows how it has happened, which is why it hasn't been resolved yet. My personal idea is to add a debug trace that throws an exception and catch it when the function performs the cleanup; then, we can write the stack trace to a file and report it here. My second idea is to compile the Godot Engine from its source code. While developing our game, we can utilize the debugging features in Visual Studio. This way, if the reset/clear bug occurs, we'll be able to set a breakpoint and begin debugging promptly to capture the issue. As for me, I'm currently busy with a full-time job and studying AI-related topics to incorporate into my game, so I won't be significantly involved in working with Godot, at least until next year. However, you can take the lead. You can find the script to build the Godot Engine from source, enabling C# support and generating a Visual Studio Project, in this link. To run it, use PowerShell: |
Can confirm It happens constantly using Rider & Godot .Net 4.1 . It is pretty frustating. |
I have been hit by the bug again, and I was again able to resolve it by clearing out all the files inside the |
There are precisely zero circumstances where the godot engine should EVER be writing to those C# sciptts if you are using an IDE. Start with that..... |
Happened on Godot 4.1, twice I just think that the editor should not have the access or cache the script anyhow.
which means that simple opening the project somehow could ruin your code |
If user dont intent to use the embeded script editor, can you simple provide an option to not allow any writing to code files overall? So that only external applications can make changes to the code files. That can prevent the damage before actually locating the actual cause |
Hi @guoboism, I share your concerns about this bug. However, I'm not certain if randomly adding code to the codebase will resolve this issue since we don't know its root cause. This bug seems to occur when moving a file and for others when they save their work. It appears to be related to resource saving, but the exact cause remains unknown. My current workaround for this bug is to use Visual Studio Code. When it occurs, I can simply press Ctrl + Shift + P -> Local History: Find Entry to Restore to recover the previously saved data. Additionally, I have developed a practice of periodically closing and reopening the engine after the editor displays some errors that could potentially cause state changes. This is because I never encounter this bug when the editor is freshly opened. This practice helps ensure that I don't encounter the bug, which could potentially erase all of my work. |
@nongvantinh Think about this: if there is no embeded script editor, what on earth does Godot need to modify the code files for? An engine should only read, compile and run the code. |
Hi @guoboism, It's actually more than just a C# script; the editor can save various types of files, including Resource files (.res), Scenes (.tscn), Import data (*.import), and more. They all use the same saving mechanism. When I work with Godot 4.1-stable, I sometimes encounter the editor wiping all the custom data I've set for the *.res files. However, when I close it and reopen it, that data comes back as if nothing has happened. We need more people to dive into the source code to gain a deeper insight into this issue so that we can identify the possible root cause. Given the current state of the engine, which has recently undergone a massive rewrite, we shouldn't expect too much. The core team members have a lot of work to do, and they don't have enough resources to allocate to this particular problem. Just keep in mind the workaround I provided above, and you won't be held back by this bug. |
Hi @guoboism, After dragging and dropping the C# file: It performs a lot of operations that include getting a list of files, which will have new paths as a result of this operation. Then it calls the godot.Debugging.-.Microsoft.Visual.Studio.2023-09-18.17-59-08.mp4For scene saving (Ctrl + S), it calls godot.Debugging.-.Microsoft.Visual.Studio.2023-09-18.18-08-01.mp4The problem with Ctrl + S is that it retrieves data from the cache and saves that data again. This action could potentially override the changes you just made and cause the script to clear, reset, or revert. |
@nongvantinh So what is the plan? |
Hi @guoboism, It can be fixed by anyone, and they can contribute by creating a pull request for others to benefit from their fix. However, the code I showed above is the way the engine works, and it may not be the root cause. The bug may be elsewhere, where the engine cannot detect that the file has changed and needs to update the cache resource accordingly. |
#43990 |
It's happening with me as well trying to do the first steps tutorials on 4.1.1. Pretty frustrating. I've been enjoying Godot so far, but this is a showstopper. If the editor can just wipe out my code in an external editor (VS) then this makes Godot a no go for serious production work. Prioritize this bug ASAP. With the amount of attention Godot is getting right now from experienced Unity developers looking for a new path forward, having issues like this is a quick way to kill the goodwill and interest. |
Since you have only followed the first steps of the tutorials, your project is considered a minimal reproduction project. Could you please try to reproduce the step that causes the bug to occur? Because without that, I would have no clue where to look. |
Thanks for the quick response! I've been trying to figure out what was causing it but haven't been able to reproduce it reliably. Sometimes it happens after clicking the script icon when VS isn't open. Instead of loading the work you've done, VS will load a script in whatever form you selected when creating it. I've also had it happen after saving via Ctrl + S and then switching window focus back to VS. You can see your code disappear and the script revert to a newly created one. What I've also noticed is that once it happens during a session, it tends to happen a lot more. I've been working through the 3D tutorial and it's been fine for a few hours now. If I can find a way to reliably reproduce it I'll let you know. |
Hi @guoboism , Would you mind taking some more time to describe the details of each step you take? Alternatively, a short video recording of what you do may suffice. Edit: I can reproduce it now. If the following step is as you described above, then just a thumbs-up is enough.
The following is for further analysis of the issue:Try with external editing:
Try with Internal editing:
I reenabled the external editor, Visual Studio Code, again. However, this time, the internal editor still opened the "new_script.cs." Then I opened the "new_script.cs" in VS Code, made changes, saved it, and came back to repeat steps 9 to 10 while the internal editor was still open. This time, the added code was still there. I'll try to take more time to trace the flow of the code in each scenario to see what happens and try to fix it if it is within my skill. |
I will also try to keep an eye out for the circumstances that caused it on my end, but last night I ran into the exact same issue while going through the 3D tutorial. Happened a couple of times but don't yet know my exact sequence of events, mainly ran into it while trying to see if there was any way to get the signal code to write itself in C# when hooking up a signal to a node. |
It is confirmed that the guess I gave above is correct. The cache system does not recognize the I'll dig deeper into the case to understand why. The Pull Request will come in 2-3 days. |
in v4.2.2.stable.official [15073af] : Godot resets entire script and code file when connecting a node signal to a function in an existing script file. Why would it even touch the script when i'm connecting it INTO a script that has functions already? I'm using visual studio code for editing the Godot script files. I'll change to 4.3 milestone, to see if that helps |
In v4.3.dev5.official [89f70e9] When running the application and changing a script when the app is still running, the script will be reverted back to older state if the app is running into an error. If i should know better than to edit scripts when the app is running, never mind this comment. |
@lightfinesthour The fix for this issue should be included in Godot 4.3 dev 6. Try it out and if you still have issues with scripts reverting their content, please open a new issue. |
Alas it is not fixed for me in 4.3. Real shame. Not as frequent but I still get the code roll backs when switching between editor and VS. It does destroy hours of work and lead to puzzling debug sessions. |
The issue occurs when a script in Godot automatically opens in the Godot editor upon encountering an error. If you're editing the code in VSCode and rerunning the game, Godot still uses the version of the script that was previously opened (and unchanged) in its own editor. To fix this, you have to manually close the script in Godot, then edit and save it in VSCode again before running the game. This can we fixed is we stop this behavior if external code editor is set. (Forgot to mention, this happens in both gdscript and csharp) |
So, I'm using Visual Studio 2022 and C# for 99.9% of my script work. I can't see where (in the godot Editor) the C# scripts are "open" to close them. Not on the scripts tab for sure? Also, I wonder if there is a file permission clash as I sometimes get the "save as" box pop-up in Visual Studio (after a Ctrl-S) for an existing script - This is usually the red flag for rollback behaviour. Anyway, I'm SO aware of this gotcha now I tend to try a quick editor invoked scene build and run and watch the visual studio editor window like a hawk (Ctrl-Z to undo the reversion, save, try again, etc...) with each code iteration. Not great. (Godot 4.3) |
Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.
Godot version
3.3.2.stable.mono.official
System information
Windows 10
Issue description
As the title says, sometimes, godot resets/reverts/clears c# script file contents for reasons unknown.
It's hard to pinpoint exactly where or why it happened (not the first time i experienced this), but i recorded for a while and tried to reproduce it and 'luckily' caught it 2 times in a row - See video:
GodotTrashingScripts.mp4
Here it seems to have been triggered by opening the project, using the 'Build' option, then doing a 'Save All' (ctrl-s).
In my case rider (IDE) then reloaded the changed file from disk, so i reverted it (undo) to reclaim my missing script content (but it's not related to rider as i can see the content vanishing even from other editors as well).
Steps to reproduce
Not sure, in my case here 3 specific files seemed affected but no other script. These are used in resources and are toolscripts, maybe that matters somehow, but others that are also used in resources didn't seem to be affected. And i found no steps to reliably trigger it, but it happens somewhat frequently.
I'll try a bit more to see if i can find a reliable MRP
Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered: