Corrupted files because a code? (Help me to understand)

Godot Version

4.3

Question

This error is showing after execute a new code:

E 0:00:00:0870 _parse_ext_resource: res://Objetos/Jugadores/jugadormuerte.tscn:64 - Parse Error: [ext_resource] referenced non-existent resource at: res://Objetos/Jugadores/jugador.tscn
<C++ Source> scene/resources/resource_format_text.cpp:159 @ _parse_ext_resource()

Basically i have a scene for player and another for player_death.

player has in script a PackedScene var that let me drop in any scene, player_death for this case.

player_death has same logical, a PackedScene var for player.

And you get it, if player got hit, this instantiate player_death using de PackedScene var, and when player_death is out the screen using a VisibilityNotifier2D, then instantiate a new player.

How can i fix it? Help meeeee please

Sounds like this scene doesn’t exist in your file system

sounds but it does exist!

i have a main scene called: text_player
this scene contains a tilemap and the player scene spawned just the main_scene starts. Then if I press number 5 in keyboard, then the player_death is instantiate. but every thing runs fine auntil player_death tries to spawn player once again!

Could you screen shot your filesystem and/or paste the script?

Check this out:

excuse my english bro! lol XD no fluent english speaker at all. I hope you can help

very strange, I think I’ve seen this before, maybe an engine bug.

Can you use @export_file("*.tscn") instead of packed scenes for your exports? Then load the scene before instantiation e.g.

@export_file("*.tscn") var jugador: String

func _ready() -> void:
    timer.timeout.connect(spawn_player)

func spawn_player() -> void:
    var scene: PackedScene = load(jugador)
    var instance: Node = scene.instantiate()
    get_tree().root.add_child(instance)
1 Like

My guess is that you are losing the reference to player1 before you get there.

But as always, it is nearly impossible to tell when you have to scrub back and forth in a video to look at the code and not all the code is even in the video.

Can you post the code where we find the player1 variable?

It sounds like you have a cyclic dependency problem there.

From what I saw in your video…
“PlayerScene” has a PackedScene to “DeathScene” scene.
And “DeathScene” has a PackedScene to respawn the player
So because @export var preloads things, it’ll enter a cyclic dependency infinite loop.

Player will preload the “DeathScene”, that has a “PlayerScene” which is then preloaded… and that has a “DeathScene” that is preloaded… which has a “PlayerScene”… and so on and so on…

The “easy” way to solve this without changing how your script works, is to use a “load” inside the “player_death” to instantiate the player scene… note that it is “load”, not “preload”.
The downside is that you’ll have to hardcode the asset path.

You are going to have to remove the @export packedScene from player_death
And load the player scene with something like instead:

var player_instance = load("res://player_scene.tscn").instantiate()

A bit of info on the error:

Older versions of Godot would just crash your game, but Godot 4.3 prevents you from loading cyclic files instead of crashing the game… which is why you got the error message you can’t load the file, that the resource doesn’t exist.

3 Likes

Bros!! You are amazing, you solved my problem! <3 I’m so thanksfull by this responses! <3 THANK YOU SO MUCH!

BLESSINGS

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.