I have a GDNative class that looks like this:

class Level : public godot::Node2D {
  GODOT_CLASS(Level, godot::Node2D);
  Level() {}
  void _init();
  void _ready();
  void _physicsProcess();

  godot::TileMap* m_tilemap = nullptr;
  int m_foobar;

  static void _register_methods() {
    using namespace godot;
    register_method("_ready", &Level::_ready);
    register_method("_physicsProcess", &Level::_physicsProcess);
    register_property<Level, int>("base/foobar", &Level::m_foobar, 16);

How can I pass a tilemap to Level from the Godot editor?

Things I've tried so far:

  • register_property<Level, TileMap*>("base/tilemap", &Level::m_tilemap, nullptr); The property shows up in the editor, but I can't edit it.
  • Calling get_node("TileMap") from _ready(): returns a Node, not a Tilemap, and dynamic_cast doesn't work because Node has no vtable.

Is there a template equivalent to Node::get_node()? Or is the only solution to use a reinterpret_cast?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.