Failed to instantiate scene state of "snake_body.tscn", node count is 0. Make sure the PackedScene resource is valid

Godot Version

4.2.2

Question

  • I have remade this simple scene twice now.
  • I am unable to open and edit via the editor
  • I can still run and play the game fine
  • I have not moved/renamed any of the assets used in this

tscn file:

[gd_scene load_steps=4 format=3 uid="uid://prhteg6w4hrg"]

[ext_resource type="Texture2D" uid="uid://6wqd328qacc4" path="res://images/snakehead.png" id="1_ae0xp"]
[ext_resource type="Script" path="res://object_scenes/snake_head.gd" id="1_lk370"]

[sub_resource type="CircleShape2D" id="CircleShape2D_24ejs"]
radius = 47.0425

[node name="Snake_Head" type="CharacterBody2D"]
script = ExtResource("1_lk370")
speed = 300

[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.66, 0.66)
texture = ExtResource("1_ae0xp")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_24ejs")

So everytime you create this scene it gets corrupted?

Correct, I haven’t tried a third time yet as it’s frustrating but two in a row is very weird

And the resources you are using in this scene are not corrupted? I can only ask you to double check if all the paths are correct. Worst case you can try to delete every file associated with this scene and create the scene again

I’ve already deleted and recreated it, and even though it claims to be corrupted, the game runs fine as is, I just can’t edit that scene anymore

Maybe its something with godot, “remembering” that this scene is corrupted eventhough it isnt

I’ve got same thing. Scene got corrupted. When i make a copy of it its opens just fine.

I had the same problem, and finding your question helped me find a solution.

What seemed to cause this for me was renaming the scene. If I were to hazard a guess, the error was caused by Godot still remembering that the old name referenced the nodes in the scene, and being unable to properly reference the nodes in the freshly renamed scene. However, I haven’t looked at Godot’s backend and wouldn’t know where to look to verify this.

What fixed it was copying all the nodes in the scene and deleting the scene, then making a new scene and saving it with the same name as the deleted scene.

how this solution would look for you is

  • open “snake_body” scene
  • shift + left click the top and bottom nodes in the tree
  • ctrl+x (cmd+x on Mac)
  • delete the “snake_body” scene
  • create a new scene
  • select “paste from clipboard”
  • save new scene as “snake_body”

If there are any corruption issues with the original scene, this process should divorce the nodes from the corruption completely, and shouldn’t break any code that used preload("res://snake_body.tscn"). However, this will decouple the scene from any @export functions, so you’ll need to drag the scene back into any nodes that referenced it using that function.

If this doesn’t work for you, I’m happy to try debugging the issue further, it’s possible there are other ways to cause this error other than renaming scenes.

Edit: fixed formatting

hold on, I opened the scene again today and now the new scene is also experiencing the same error. It was working fine last night. Seems my fix doesn’t work after all.

If this is a corruption error, it shouldn’t be affecting different scenes of the same name, so now I’m stumped on how to fix this.

Edit: instantiating the scene via the right-click menu in the file system works fine, and the scene has all the nodes it’s supposed to have. Instantiating the scene with preload("res://[scene].tscn").instantiate() does not work, and preload("res://[scene].tscn").can_instantiate() returns false. This seems like an issue with the preload() function, not the scene.

Changing from preload to load seems to work for me.

5 Likes

bruh thank you

The issue might be a merge conflict caused by working on the project simultaneously on different machines. This happened to me by having the project open on laptop and desktop at the same time. Digging around, I found this reddit post, with instructions on how to change the .tscn-file with a text editor. The trick is correcting duplicate id’s of loading resources caused by the merge conflict.

https://www.reddit.com/r/godot/comments/6ntejk/tips_how_to_fix_merge_conflict_with_tscn_files/