0 votes

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?

asked Mar 15, 2019 in Engine by Olivier FAURE (12 points)

Please log in or register to answer this question.

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 How to use this Q&A? before posting your first questions.