godot: Scene is invalid/corrupt according to the Godot editor, but works normally ingame

Godot version

4.1

System information

Ubuntu 22.04.2 LTS 22.04 - Vulkan (Forward+) - integrated Intel® HD Graphics 4400 (HSW GT2) () - Intel® Core™ i7-4600U CPU @ 2.10GHz (4 Threads)

Issue description

This is the tscn file:

[gd_scene load_steps=2 format=3 uid="uid://bgrpmpmsi1ae2"]

[ext_resource type="Script" path="res://src/UI/LevelEditor/UserLevelsMenu.gd" id="1_0uvtn"]

[node name="UserLevels" type="Control" node_paths=PackedStringArray("initial_focus")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_0uvtn")
initial_focus = NodePath("MainContainer/Create")

[node name="MainContainer" type="VBoxContainer" parent="."]
layout_mode = 0
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -40.0
offset_top = -20.0
offset_right = 40.0
offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2

[node name="Create" type="Button" parent="MainContainer"]
unique_name_in_owner = true
layout_mode = 2
button_mask = 0
text = "#create_new"

[node name="LevelContainer" type="VBoxContainer" parent="MainContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/separation = 9

[connection signal="pressed" from="MainContainer/Create" to="." method="_on_Create_pressed"]

It results in this: image

And the following error: “scene/resources/packed_scene.cpp:92 - Condition “nc == 0” is true. Returning: nullptr”

It also creates adds an empty scene in the scenes tabbar, and when I click on it, it automatically closes, throwing the following two errors:

  • editor/editor_data.cpp:683 - Index p_idx = 2 is out of bounds (edited_scene.size() = 2).
  • editor/editor_data.cpp:745 - Index p_idx = 2 is out of bounds (edited_scene.size() = 2).

Steps to reproduce

Unknown, only happened to one of my scenes 😦

However, I can give some details surrounding the scene. I made it at some point during 4.0’s alphas. I probably never touched it since. In my git, it says it’s been unchanged for 5 months. However, I opened it yesterday. Not doing any changes to it, just opening it. It has a simple script, which opens normally.

Minimal reproduction project

Couldn’t, this happened on my major project (far too big to post)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 33 (10 by maintainers)

Most upvoted comments

Just to add to this thread. I have a fairly large project. I just now hit this randomly in 4.2 stable.

Replacing “preload” with “load” did fix the problem. And I don’t have any name clash issues like others have reported.

This issues keeps reoccurring for me (4.2 rc2)…

Updated instruction on how to (temporarily) fix, since the above instructions not always worked for me (do each step for each corrupted scene file, as I found there can be more than one):

  • Duplicate scene file in external editor
  • Open duplicated scene in godot, overwrite on the original corrupted scene
  • Close all scripts and open scenes in the editor, close editor
  • Delete all files in the .godot/editor folder containing the corrupted scene’s name (they are going to be name something like your_scene_name.tscn-editstate-2e5312b3e75d2338868814f479b1feeb.cfg)
  • Reopen editor

Here’s what working for me to fix this error: close editor, search in the .editor folder for all files containing the corrupted scene’s name (they are going to be name something like your_scene_name.tscn-editstate-2e5312b3e75d2338868814f479b1feeb.cfg), delete them, restart editor.

Reproduction project: godot-bug-mwe-1-master.zip Bee.tscn can’t be opened in editor. Seems to be caused by preload.

I’ve also been experiencing this with one the scenes in my latest project.

I think one thing that’s sometimes gotten confused along the way is that (at least in some cases) it’s the scene which is being preloaded that gets corrupted, not the the scene doing the preloading.

On testing out the repro bee project, I noticed that it only seems to happen the first time you open that project - ie. before the .godot directory is created. If you already have a .godot directory from having just opened the project, you don’t get the corruption error and can open the bee scene just fine! However, this has not been the case for my project. 😕

Got the error again, and the above steps did not help this time. What helped was: duplicate scene in a file explorer (not in Godot editor, since the error stays that way), open the duplicated scene (it opens without the error), ‘Save As’ the scene overwriting the original scene.

Here’s what working for me to fix this error: close editor, search in the .editor folder for all files containing the corrupted scene’s name (they are going to be name something like your_scene_name.tscn-editstate-2e5312b3e75d2338868814f479b1feeb.cfg), delete them, restart editor.

Had the exact same issue on 4.1.3 stable, and this fixed it!