0 votes

Jan2022
Hi,
I need help with editing and repacking a PackedScene, in the following code, why does the "deleteme" remain undeleted in a new instance after repack?

editme.tscn:

-tobeinstance
   -deleteme
   -keepthisnode

unpackrepack.gd:

static func own(node, new_owner):
    if not node == new_owner and (not node.owner or node.filename):
        node.owner = new_owner
    if node.get_child_count():
        for kid in node.get_children():
            own(kid, new_owner)
func _ready():
    #load as orphan
    var bi=load("editme.tscn").instance()
    #debug
    print("\n","bi new instance:")
    bi.print_tree()

    #delete one node
    var d=bi.get_node("deleteme")
    bi.remove_child(d)
    d.owner=null
    d.free()
    #debug
    print("\n","instance after node removal:")
    bi.print_tree()
    print("get_node('deleteme'): ",d)

    #wrap with new node
    var node = Node.new()
    node.add_child(bi)
    own(node,node) #recursive own

    #pack all
    var ps = PackedScene.new()
    ps.pack(node)
    #debug
    print("\n","bundled scene:")
    print(ps._bundled)

    #add new instance into tree
    add_child(ps.instance())
    #debug
    print("\n","why does 'deleteme' remain?:")
    get_tree().root.print_tree()

output:

bi new instance:
.
deleteme
keepthisnode

instance after node removal:
.
keepthisnode
get_node('deleteme'): [Deleted Object]

bundled scene:
{conn_count:0, conns:[], editable_instances:[], names:[, Node, tobeinstance, Spatial], node_count:2, node_paths:[], nodes:[-1, -1, 1, 0, -1, 0, 0, 0, 0, 3, 2, 0, 0, 0], variants:[[PackedScene:1266]], version:2}

why does 'deleteme' remain?:
.
unpackrepack
unpackrepack/@@2
unpackrepack/@@2/tobeinstance
unpackrepack/@@2/tobeinstance/deleteme
unpackrepack/@@2/tobeinstance/keepthisnode
Godot version 3.4.2
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.