Skip to content

[gdextensions] Registered classes are ticking in editor #709

Closed
@RedwanFox

Description

@RedwanFox

Godot-cpp commit 8ead641
godot4 commit be52c5bf6ee7f8e1181f42f7c68fca9f8aaaa2b6
Windows 10

Using example code below place Example node in scene tree in editor and it will be spamming in log as if it was tool class.

Are there any flags or other correct way to register runtime only class?

#include <godot/gdnative_interface.h>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/classes/node.hpp>

using namespace godot;

class Example : public Node {
	GDCLASS(Example, Node);

	Example() = default;
	~Example() = default;

public:
	void _init()
	{
		godot::UtilityFunctions::print("Init!");
	};
	void _process(float delta) {
		godot::UtilityFunctions::print("Delta ", delta, " seconds");
	}

protected:
	static void _bind_methods() {
//		ClassDB::bind_method(D_METHOD("_init"), &Example::_init);
		godot::UtilityFunctions::print("Bind methods!");
	}
};

void register_types()
{
	ClassDB::register_class<Example>();
}

void unregister_types()
{
}

extern "C"
{
	// Initialization.

	GDNativeBool GDN_EXPORT library_init(const GDNativeInterface* p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization* r_initialization)
	{
		godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);

		init_obj.register_scene_initializer(register_types);
		init_obj.register_scene_terminator(unregister_types);

		return init_obj.init();
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions