Error when setting global position (inside-in-tree, dirty Transform3D?)

Godot Version

4.6

Question

I get a inside-tree-error (dirty Transform3D?) when setting the global position.

Error message:

Condition "!is_inside_tree()" is true. Returning: Transform3D()

The stack trace looks normal (no emit() or await etc.)

  <C++ Source>  scene/3d/node_3d.cpp:642 @ get_global_transform()
  <Stack Trace> lifecycle.gd:23 @ init()
                enemy.gd:12 @ init()
                tutorial.gd:50 @ process_wave()
                tutorial.gd:43 @ process()
                main.gd:34 @ _process()

This snippet triggers the error:

func init(root_node: Node, enemy: Enemy, _spawn: Dictionary, _timeline: Array):
	spawn = _spawn
	timeline = _timeline
	enemy.global_position = spawn.coords # <- Offending line

What did I do wrong? How can I fix that?

You need to add the node to the scene tree before setting its global position. Global position only makes sense in the context of the whole scene tree hierarchy.

1 Like

Thank you for the explanation. The negated assertion threw me off.