Missing, unrecoverable scenes? PackedScene bug/issue? Broken dependencies?

Godot Version

4.4

Question

Okay, this happened to me twice already, and both times I lost a full days worth of work so I’m little pissed off right now.
I’m currently working on an fps where you can pick up and drop weapons.
I created a separate ‘in-world’ placeholder RigidBody gun and wrote a script for it that’s nothing but the pick up logic.
When you ‘pick up’ the placeholder it instantiates a packed scene into the players hand, and then it calls queue_free() on itself
The packed scene is a Node3d version of the weapon, when you drop that it instantiates the packed scene of the placeholder RigidBody version back into the world, and then it calls queue_free() on itself.
So both the in-world placeholder and the actual in-hand weapon use the same logic to instantiate one-another and then make themselves disappear.
HOWEVER, after I set this up, I close Godot, I open it again, and it tells me that it couldn’t load the placeholder scene, due to **missing dependencies **
Since it can’t load that scene, it also can’t load the other weapon scene that references it
AND it can’t load the entire world scene either, since that references both.
So now my entire project is destroyed and I have to start from 0.

Did anyone else come across this issue? Is this specifically because of the way I’m trying to use PackedScenes? Is there anything I can do to fix this?
“Fix dependencies” does nothing.
I did NOT rename or manually delete ANYTHING.
I can still see everything in the assets folder exactly where they need to be.
It just “forgot” how to reach them.

Did you use version control ? Can you see a difference in the project before and after your set-up ?

Weird. Also frustrating. What exactly are the missing dependencies? It’s possible that this is due to circular logic, i.e. the engine doesn’t know which comes first, the chicken or the egg, and when it tries to create one, it looks for the other and goes round and round.

To try fix this, what I would do is move both those scenes out of the folder structure (when the project is closed). Then I would open it up. The level will complain, and you can say open anyway. The broken dependencies will be resolved by the engine deleting the gun lying around. You now have a working project.

Then I would drop in one of the scenes without the other, back in the structure. See what complaints you get. Fix them so they go away without the other scene being in there - then add the other scene back in.

My best guess on what you’ve said is that both scenes have an exported variable, each containing the other. If that’s the case, delete them and replace it with a const that you pull from.

const GUN = preload("res://weapons/gun.tscn")

You can make it easily by dragging the scene you want a reference to into the script editor at the place where you want the variable (consts go at the top) and press Ctrl before releasing. It’ll write the whole line.

Then just use GUN in your instantiation code.

func on_body_entered(body: Node3D) -> void:
	var gun = GUN.instantiate()
	body.add_child(gun)

Again, just a guess.

Thank you!
Yes, it’s most likely due to circular logic. I’m very new to coding/Godot/game design and I wasn’t aware that this could be a problem.
The missing dependencies are the two scenes that I loaded as PackedScenes, so it’s more than likely that the problem is exactly what you described.
I will try to salvage the project based on your suggestions.
Thank you!

1 Like