Godot Version
4.4 windows
Question
Hello all,
To avoid the need to surround the code with if isEditor (or something similar) like in old Godot versions, I just load all my classes with GDREGISTER_RUNTIME_CLASS.
But I’m not sure if it’s the right way to do it, as I have many classes.
What do you think is the right way to register the classes, and what is the impact?
This is how it looks
#include "register_types.h"
#include <gdextension_interface.h>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>
#include "player.h"
#include "event_system.h"
#include "items/interactbles.h"
#include "items/pickuppable.h"
#include "items/interactble_raycast3d.h"
#include "bulletins/bulletin.h"
#include "bulletins/bulletin_controller.h"
#include "bulletins/interaction_prompt.h"
#include "managers/stage_controller.h"
#include "resources/item_resources/item_resource.h"
#include "resources/item_resources/resource_stick.h"
#include "resources/item_resources/resource_stone.h"
#include "resources/item_resources/resource_plant.h"
#include "resources/crafting_blueprint_resources/crafting_blueprint_resource.h"
#include "resources/crafting_blueprint_resources/crafting_blueprint_cost_data.h"
#include "managers/inventory_manager.h"
#include "bulletins/player_menus/player_manubase.h"
#include "bulletins/player_menus/crafting_menu.h"
#include "ui/custom_nodes/inventory_slot.h"
#include "ui/custom_nodes/crafting_button.h"
using namespace godot;
void initialize_gdextension_types(ModuleInitializationLevel p_level)
{
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
GDREGISTER_RUNTIME_CLASS(Player);
GDREGISTER_RUNTIME_CLASS(Interactble);
GDREGISTER_RUNTIME_CLASS(Pickuppable);
GDREGISTER_RUNTIME_CLASS(InteractbleRaycast3D);
GDREGISTER_RUNTIME_CLASS(Bulletin);
GDREGISTER_RUNTIME_CLASS(InteractionPrompt);
GDREGISTER_RUNTIME_CLASS(EventSystem);
GDREGISTER_RUNTIME_CLASS(BulletinController);
GDREGISTER_RUNTIME_CLASS(StageController);
GDREGISTER_RUNTIME_CLASS(ItemResource);
GDREGISTER_RUNTIME_CLASS(ResourceStick);
GDREGISTER_RUNTIME_CLASS(ResourceStone);
GDREGISTER_RUNTIME_CLASS(ResourcePlant);
GDREGISTER_RUNTIME_CLASS(InventoryManager);
GDREGISTER_RUNTIME_CLASS(PlayerMenuBase);
GDREGISTER_RUNTIME_CLASS(InventorySlot);
GDREGISTER_RUNTIME_CLASS(CraftingBlueprintResource);
GDREGISTER_RUNTIME_CLASS(CraftingBlueprintCostData);
GDREGISTER_RUNTIME_CLASS(CraftingButton);
GDREGISTER_RUNTIME_CLASS(CraftingMenu);
}
void uninitialize_gdextension_types(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
}
extern "C"
{
// Initialization
GDExtensionBool GDE_EXPORT example_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization)
{
GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
init_obj.register_initializer(initialize_gdextension_types);
init_obj.register_terminator(uninitialize_gdextension_types);
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
return init_obj.init();
}
}