• Godot HelpC++
  • In a GDExtension module, _ready is called in the editor

v4.1.1.stable.official [bd6af8e0e]

I made a simple GDExtension module to increase performance for a key node.

When I change_type of the node in question to the new node type written in c++, the editor crashes with the following error message.

ERROR: Node not found: "NavigationAgent3D" (relative to "/root/@EditorNode@17637/@Control@697/@Panel@698/@VBoxContainer. at: (scene/main/node.cpp:1620)

It seems the _ready func is called from within the editor. The _ready func is this:

void Agent::_ready() {
navigation_agent = get_node<NavigationAgent3D>("NavigationAgent3D");
navigation_agent->set_path_desired_distance(0.5);
navigation_agent->set_target_desired_distance(0.5);
anim_player = get_node<AnimationPlayer>("AnimationPlayer");
anim_player->play("walking");
}

  1. I don't expect _ready to be called at all until I actually run the project.
  2. The NavigationAgent3D node is where it's supposed to be, but clearly the engine is looking for the node in a completely different part of the scene tree.

Any ideas?

Yeah, nodes you write with gdextension are lower level than gdscript and comparable to an engine node. Engine node's run in the editor and their callbacks are called because they are nodes in a scene tree.

You can guard game play behavior like

if (!Engine::get_singleton()->is_editor_hint()) {
    // Your game play only code.
}