Exported packed scenes are turned null on scene opening

Godot Version

4.4

Question

any idea why my exported packed scenes are set to null when i open container scenes?

im developing a game and to navigate through the games structure i need to change scenes frequently , for example :
main menue → house → level map
so i save the packed scenes in @export variables so for example pressing ui back button changes the scene to main menu , but there is on big problem , when ever i open a scene , all exported variables which i have set resets to null O_O !

IM FRUSTRATED !
i tried going with scene pathes , that works but only on pc and my target platform is android

*no these packed scenes arent on auto loads
*i tried removing/saving and adding/saving variable , did not work
*yes i checked and the variables are set in the editor


Hi,

I’m definitely not sure about what could cause such an issue, it seems more like an engine bug.
I’ve researched some answers and read some things that could help you here: Godot @export var is Nil in _ready function and https://www.reddit.com/r/godot/comments/1b90b2y/export_variable_keeps_getting_set_to_null/

One question though, how is your main menu scene instantiated? I suppose you’re placing it by hand or instantiating the main_menu.tscn file, right? Because such issues can happen if you create instances in code using the new keyword. Definitely doesn’t look like something you’re doing, but I just want to make sure of that.

1 Like

well , it seems like an engine bug to me as well .
the scenes are opened via get_tree().change_scene_to_packed(scene_var) , and one of the is default scene actually

and it even corrupted my scenes :slight_smile: :


i am frustrated , i faced this error ~45 days ago and i was forced to switch my entire system on file paths but unfortunately i just relized those dont work on my target platform (android)

im just frustrated , no body knows what to do and im here with a project that ive been working on for at least 3 whole months .

for know i try to revert last edit , so at least i can open the scene , tell me if you found any thing , ty .

I did not even know change_scene_to_packed existed, tbh. In the game I’m currently working on, I’m using a container scene that instantiates and deletes scenes on the fly, which means I’m just using instantiate. Not saying my architecture is better, but that may be related to the usage of that scene changing function.

Maybe some useful info here? Change_scene_to_packed not working after it's worked so far
You may have already read those threads, but I prefer sharing those just in case.


If using exported variables to access your scenes doesn’t work as some values get null or corrupted, maybe you could use another way.
For instance, reference the scenes in a script you can access from anywhere (using an autoload, maybe) using the scenes paths:

var main_menu_scene: PackedScene
var house_scene: PackedScene

func _ready():
    main_menu_scene: "scenes/main_menu.tscn"
    house_scene: "scenes/house.tscn"

I know that’s not the solution you’re looking for, but if that is more stable and if you don’t have tons of scenes to include, something like this may do the job quiet well.

Thank you for your suggestions but i dont think its related to change_scene_to_packed() since even the main scene opened by the engine it self has this issue

And i have a ton of scenes , the proble is that its not just one scene , its persistant on the whole project

Its a children edjucational game with 100s of levels , doing it hard coded wouldnt make any sense :frowning:
I wish i was better at coding so i could dive into cpp core of the engine to see wtf is happening !

Since i think at some point i got glimps of an cpp eror

Can you try on a new empty project to see if the same will happen? Because it’s definitely not supposed to be doing that.

here is some c++ erors i get when i re open project (and scene files get corrupted):

— Debug adapter server started on port 6006 —
— GDScript language server started on port 6005 —
ERROR: scene/resources/resource_format_text.cpp:282 - Parse Error: Busy. [Resource file res://game/place_select.tscn:23]
ERROR: Failed loading resource: res://game/place_select.tscn. Make sure resources have been imported by opening the project in the editor at least once.
ERROR: scene/resources/resource_format_text.cpp:282 - Parse Error: Busy. [Resource file res://game/main_menu.tscn:252]
ERROR: Failed loading resource: res://game/main_menu.tscn. Make sure resources have been imported by opening the project in the editor at least once.
ERROR: scene/resources/resource_format_text.cpp:282 - Parse Error: Busy. [Resource file res://game/main_menu.tscn:252]
ERROR: Failed loading resource: res://game/main_menu.tscn. Make sure resources have been imported by opening the project in the editor at least once.
ERROR: scene/resources/resource_format_text.cpp:282 - Parse Error: Busy. [Resource file res://game/place_select.tscn:23]
ERROR: Failed loading resource: res://game/place_select.tscn. Make sure resources have been imported by opening the project in the editor at least once.
ERROR: scene/main/window.cpp:992 - Attempting to make child window exclusive, but the parent window already has another exclusive child. This window: /root/@EditorNode@21272/@Panel@14/@DependencyEditor@1063, parent window: /root, current exclusive child window: /root/@EditorNode@21272/@Panel@14/@DependencyErrorDialog@862

hello again , i just set up an other test empty project an i ran to the same problem again , let me explain

here we have the project set up:
we have two Scene+script : test_level and test_level_2

they are almost the same , each one of these scenes have an exported packedScene variable and a button which changes scene to the packed scene stored in the variable .

the exported packed scene variable for each scene is referring to the other scene , so ideally we should be able to go back and fourth between these scenes .
test_level :


test_level_2:

but that does not happen !

what happens is that the test_level (which is loaded by default bc its selected as main scene ) , acts as expected its loaded , the exported PackedScene variable isn’t null as you can see in the picture :


so as expected when i press the next level button , it changes the scene to the PackedScene it has stored (you can also see it wasn’t looking at output “Scene transition OK!”):

but the scene which is loaded , has its variable set to null ! you can see it in the inspector , and also when you click on the last scene button it prints “scene is null” :

and the most fun part , you close and re open the project you see a bunch of errors :

you can still run the game with same problems , but you can no longer open any of those scenes in the editor :


you cant fix the dependencies since there isn’t any thing lost or wrong any way , as you can see every thing is set to correct path by default , but weather you don’t fix it or you reselect those dependencies in fix dependencies panel , you cant open the scene , you will face the error bellow :

you can replicate my problem now i guess

yup ! replicated it again using my not_mono Godot and the issue persists !
so for any on asking the .net sdk error on last image before is irrelevant .

I tested this and it seems you’re right, it seems like a bug… I also found a couple mentions about it on the Internet, even reported officially here, give it a thumbs up: