For my level 3, if I put level or level_2 as the “next level,” running the project (F1) or running the current scene (F6) would exit out immediately. It works if I put the player scene as the next scene. Why? Is this a limitation of change_scene_to_packed?
Morning and welcome to the community
Sorry its taken alot longer to reply, was trying to do some digging to see what was happening and honestly, its still not making alot of sense
but, it would seem that if we put an already ‘used’ or referenced level in the “next_level” slot in the inspector on the levels, it treats that as a cyclic reference and just stops with memory leaks showing in the console window.
so, my takeaway from this, is that i agree that there is some limitation with using the packedscene approach in the way we are using it.
there are possible workarounds that ive tried.
one being just declaring a dictionary to store all the level names.
the other being using the change_scene_to_file()
that one needs a couple little tweaks to the script and its not as intuitive.
Thanks for the reply. If change_scene_to_packed() would result in cyclic reference, I guess I will try to avoid using it.
I have been using change_scene_to_file() in my other projects and when following other tutorials, so I have not run into this problem until now.
Can you elaborate a bit more on how to use change_scene_to_packed() in combination with a dictionary with all the level names?
sorry im so late, am out of country at work just now.
but i had a little play around, just to see what i could do.
its not the best idea for larger projects, but its just a quick test.
what i did was create a new plain ‘node’ scene and add a little script to it to give me the dictionary on the inspector. then added it to the autoload.
so what i did was, i clicked the LevelLoader node, to show the dictionary in the inspector.
then added the key/value pairs, with the key as an integer, like the level number, then the value as an object and dragged the packed scene into the slot. then clicked the ‘add key/value pair’ to add it to the dictionary. and done that for all 3 levels
saved that scene and closed it , since i now had it in the autoload.
so the next thing i did was change the level script, and changed the next level to be an INT instead, so i could just pick the level number i wanted based on the KEY of the dictionary.
so in each of the levels, i changed the integer for next level to load when i get to the exit.
and made another little change on how the levels are loaded at the bottom
think thats about all i done.
like I say, its not ideal, but I wanted to see if i could do it for a test
Your solution works perfectly. Thank you so much for taking the time to write a detailed response.
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.