#Objects deleted in a scene are still there when scene is instatiated

119 messages · Page 1 of 1 (latest)

upper pilot
#

Hey, i have a tool script that generated a level out of tiles. Each tile mesh is basically a cube with all the walls, floor and ceiling.

After instatntiating each tile, script deletes the walls that connect adjacent rooms. I then moved this scene with generated level into my main game scene.

The problem is that the walls between rooms are still there for some reason, they did not get deleted and idk why and how to fix that

#

Left screenshot shows the generated level inside its own scene. You can see that there are no walls between rooms.

But on the right screenshot if i look inside the mesh, all the walls are still there.

I've tried adding again that level scene to the main scene, but still the same problem

thin mural
#

Code?

upper pilot
# thin mural Code?

Hey, here's the code. I can post it as text, i just though it would look more intuitive

vagrant thunder
#

or is it a singleton

#

if it's a singleton, it'd be outside of the active scene, so won't get cleared when changing scene

upper pilot
#

so it just seems like the state of all those instantiated tiles does not save inside the scene

#

so they all remain with all their walls

upper pilot
upper pilot
vagrant thunder
#

yea, i saw that, though I'm wondering it it's not getting it properly, for some reason

#

maybe try what this thread suggested

upper pilot
#

i saved the scene, added it again to the main scene but the walls are still there

thin mural
#

Since you're using a deferred method of removing them it may be saving before its able to remove them from the tree.

vagrant thunder
#

I'm wondering if this is a case of godot being weird with children of instanced packed scenes, and not saving their data

upper pilot
vagrant thunder
#

one thing that comes to mind is that it's a tool script, so it'll be run when instanced too

#

unless you have a manual way to generate the map

upper pilot
vagrant thunder
vagrant thunder
#

it just doesn't save that stuff, unless you enable editable_children

thin mural
#

You're trying to generate a level in the editor and then export it to a new scene right?

upper pilot
#

is there some way to avoid this?

vagrant thunder
#

add this function to the parent of this packed scene and see if it does something

#

iin _ready before you call the function

vagrant thunder
# upper pilot hm, probably that

though, It should still appear in editor. what I meant by you can't edit children is that it doesn't save changes to children of packed scenes, thinking back on this

thin mural
#

What are you using to save it?

vagrant thunder
#

the second part is where things go wrong

thin mural
#

PackedScene.pack()?

vagrant thunder
#

believe they just save it in editor

upper pilot
#

i just drag it in in the editor

vagrant thunder
vagrant thunder
#

if you open a tscn, they refer to those as intances of other scenes

upper pilot
#

here are the two scripts i used for generation

#

the one i was showing is generated_mesh.gd

vagrant thunder
#

ah, I noticed that these are also scene instances

#

these are your walls right?

upper pilot
#

those are the tiles, each tile has all the walls as children

#

but they are not shown in this hierarchy

upper pilot
vagrant thunder
#

yea, that's what editable children is for

vagrant thunder
vagrant thunder
upper pilot
vagrant thunder
#

may I see the tscn of the generated_level scene?, as in the file itself

upper pilot
#

sure, here it is

vagrant thunder
#

hmmm, so notice this?

#

it doesn't store the data of which children should be deleted

upper pilot
#

yeah true

#

hm, so it's only saved in the editor?

vagrant thunder
#

it might not persist if you close godot for eample

#

maybe try this

#

as a parameter to the instantiate function

#

default is 0

vagrant thunder
#

REmove_child removes it, but the node still ex><ists

#

just, somewhere

#

for the instantiate parameters

upper pilot
#

about walls being deleted

#

i've reopened the scene (before and after executing the script) and all that just to be sure

vagrant thunder
upper pilot
#

but didn't change anything

vagrant thunder
#

after reading this, possible one solution would be to set all this stuff to your instanced scene

#

rather than the set_editable_instance, use that code instead

upper pilot
vagrant thunder
#
    node.set_owner(owner)
    for child in node.get_children():
        recursive_own_children_to_scene(child)

recursive_own_children_to_scene(node)
node.filename = ""```
#

you'll need the func somewhere else, but yea

vagrant thunder
#

also don't use get_scene

#

@upper pilot updated the code, sry bout that

upper pilot
#

hm, it gives me error:
res://scripts/generated_mesh.gd:47 - Invalid set index 'filename' (on base: 'Node3D') with value of type 'String'.

vagrant thunder
#

ah, might be a different variable in 4.0

#

scene_file_path

#

is what it is in 4.0

#

dunno if the function is even needed in 4.0 tbh, butt always better safe than sorry

upper pilot
#

wow it works now

vagrant thunder
#

welp, thanks godot jank

upper pilot
#

and the scene seems to be saving all parameters now

vagrant thunder
#

that filesize tho

upper pilot
#

yeah haha

#

it got a lot bigger

#

thanks a lot for the help, now at least i know how to approach that problem in case i have it again

vagrant thunder
#

hmm, seems it's loading ht mesh in the scene now too

#

one thing to consider is change the name of the instanced scenes

#

might not make a huge change on filesize tbh, but it'll at least be less funky looking

upper pilot
#

what you mean by that

vagrant thunder
#

but yea, tldr for anyone reading this thread after the fact:
Instanced scenes don't save changes to children, so you have to "make local" to make the changes saved

#

if doing multi-level instancing

vagrant thunder
#

the resources of your tile packed scene are now here

#

makes sense, and not that much of the space tbh, but something I noticed is all