The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hi!

I'm writing a custom import script for .dae scenes coming out of Blender, and I'm having some issues adding new nodes to anything other than the root node. Here is my example code:

tool
extends EditorScenePostImport

func post_import( scene ):

    # adding something to root node
    var new_node = Spatial.new()
    scene.add_child(new_node)
    new_node.set_owner(scene)

    # adding something to child of root
    var new_node2 = Node.new()
    scene.get_node("Parent").add_child(new_node2)
    new_node2.set_owner(scene.get_node("Parent"))

    # adding something to grandchild of root
    var new_node3 = Area.new()
    scene.get_node("Parent/Child").add_child(new_node3)
    new_node3.set_owner(scene.get_node("Parent/Child"))

return scene

The sample .dae coming from blender is a Cube named "Parent," with child Cone named "Child." It looks like this in Blender: It looks like this in Blender:

Only the first block, adding something to root, actually works. The other blocks just do nothing.

I also tried a few other things on different scene setups, like accessing multiple children of the scene root with scene.get_children() and iterating through to add new nodes to each one, but that also did nothing - no errors or anything.

I am using the Better Collada plugin for Blender, and Godot 2.1.3. The documentation on import scripts is a little sparse, can someone provide some direction on how to accomplish this? Can nodes only be added to the root node from an import script?

Thank you so much!

in Engine by (36 points)

1 Answer

+1 vote

Hello there,

Not that I am an expert or anything, but I think a similar scenario worked for me when I added_child() "normally" in the tree, but set the owner to the scene root instead of the actual parent.

The following worked for me :

tool
extends EditorScenePostImport

func post_import(scene):
    # Adding the 'root' script
    scene.set_script(preload("res://MyScript.gd"))

    # Creating an 'Area', child of 'root'.
    var area = Area.new()
    scene.add_child(area)
    area.set_owner(scene)

    # Removing the 'shape' from a rigid body imported from Blender
    var shape = scene.get_node("Collision/shape")
    scene.get_node("Collision").remove_child(shape)

    # Adding the shape to my script generated 'Area'
    area.add_child(shape)
    # Setting 'root' as the owner of the 'shape'.
    shape.set_owner(scene)

    return scene

I think the rationale behind this is the 'owner' must be the main object(scene) described by your *.scn file; but that's really my two cents.

by (50 points)
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 Frequently asked questions and 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 [email protected] with your username.