Archive 17/01/2023.

Custom C++ components names

beldiv

I register 2 custom components in category “MY-COMPONENTS”, they have as predecessor class “Urho3D::LogicComponent”, as in tutorial:http://urho3d.wikia.com/wiki/Creating_your_own_C%2B%2B_components, but in editor they have name LogicComponent, when I expected my names (MySecondComponent,MyFirstComponent).

image

My sources:

MyCxxComponents.hh :

#pragma once
#include <functional>
#include <Urho3D/Urho3D.h>
#include <Urho3D/Scene/LogicComponent.h>
#include <Urho3D/AngelScript/APITemplates.h> 

extern  const char *  CATEGORY_MY_COMPONENTS;

typedef  std::function<void(Urho3D::Context*context)>  reg_t;
Urho3D::Vector<reg_t>   &  get_autoregistators();

#define CXX_COMPONENT(T) \
        struct T; \
        static char const  autoreg_character_name=[](){   get_autoregistators().Push( [](Urho3D::Context*context){  context->RegisterFactory<T>(CATEGORY_MY_COMPONENTS);  } );  return 'Y'; }(); \
        struct T : Urho3D::LogicComponent \
        {   OBJECT(T); \
            T( Urho3D::Context* context ) : Urho3D::LogicComponent(context)

MyCxxComponents.cc :

#include "MyCxxComponents.hh"

const char *  CATEGORY_MY_COMPONENTS = "MY-COMPONENTS";

Urho3D::Vector<reg_t>   &  get_autoregistators()
{   static  Urho3D::Vector<reg_t>   singleton;
    return  singleton;
}

extern "C"
{   extern void cxx_components_loader_entry_point( Urho3D::Context* context )
    {   for( reg_t const & reg : get_autoregistators() )
             reg( context );
    }
}

MyFirstComponent.cc :

#include "MyCxxComponents.hh"
CXX_COMPONENT( MyFirstComponent )
    {} // ctor
    void Start() override
    {}
};

MySecondComponent.cc :

#include "MyCxxComponents.hh"
CXX_COMPONENT( MySecondComponent)
    {} // ctor
    void Start() override
    {}
};
Eugene

Every object should be registered via URHO3D_OBJECT macro, at least in latest versions of Urho.

This Wiki is quite dead, I think.

Modanung

Official wiki is located mjer:

And welcome to the forums! :confetti_ball: