All Questions



bullet instancing is local to the weapon scene?

when the bullet is instances, it is added a child to the weapon-scene (I think) and not the the parent-scene (ie the level).
ie get_tree().current_scene.add_child(bullet)

Is there a reason for this?

And second question:
Does it make sense to first set the global_position and then add it as a child?
Or is this just the same as in the example you wrote.

  • Nathan Lovato replied

    The reason to add bullets as children of the weapon, which spawns them, is that you can and it works great. This means you keep an intuitive node tree where things you spawn are children of their spawner rather than ending in a completely different place in the scene tree. That can help with debugging.

    As far as setting the global position after instancing the child, there's a difference in this case: if you set the position first, it'll end up as the node's offset from the parent and position the child wrongly after adding it to the tree.

    If, however, you make the child top-level (child.set_as_toplevel(true)), meaning its position will always be global, as if it didn't have a parent, then you can set the position either before or after adding the node as a child.