App framework befudlement

Hi All!,
I’m compiling an Application framework based on the code from the ‘First Project’.
Now, i understand that this framework has one Start method, and from there you set your event handlers and what not. Now, in the examples I happily went through the extra Components like LogicComponent, and Component. However, I cannot for the life of me register a component in my Start method of the ‘First Project’.
In my main class I declare

WeakPtr laser_;


Node * laser = scene_->CreateChild “laser”;
laser_ = laser->CreateComponent Laser;

But when the main Start() gets to laser_->Start() it crashes

Correct me when I’m wrong but as soon as i declare
Node * laser = scene_->CreateChild “laser”;
laser_ = laser->CreateComponent “Laser”

the registrant of the new should be exposed and visible…it’s not!

Please Help…I know that the examples are full of extra components but they’re wrapped in the Sample framework.

Lord Fiction

Did you register the component, or are you getting an unknown component error, followed by a nullptr exception?


I believe its registered in the Component class like…
void Laser::RegisterObject(Context* context)
cout << "reg here " << endl;


Pretty close, it’s a template function=

i dunno how to do text on this!

Hi and welcome!

You don’t need to write your own main function. Instead just inherit from Urho3D::Application and write your own class App final : public Application class with overrides for Setup(), Start(), and Stop(). At the bottom of your app.cpp file write this:


i did that. the class is in the website

I dunno what you mean by that. :slightly_smiling_face:

Also, is the RegisterObject being called somewhere? And is it a static function?

In my view, there’s usually no need to wrap RegisterFactory into a RegisterObject function, btw.

I must say registering new components is quite ambitious for a newbie. Have you tried getting a bare-bones project compiled and running, e.g. just a blank window?

:musical_note: Too Many People by Leaves

Like i could pull the vehicle Sample LogicComponents .cpp and .h and put them in my project and declare
vehicle_ = node->CreateComponent*<Vehicle>

and nothing shows up registered or on console as queuing up…

It’s hard to help you without more context. Have ever successfully compiled and run any Urho3D project? That is the starting point. Also, you can use back ticks to autoformat code snippets.

``` start backticks
some code
``` end backticks
1 Like

Okay…I figured it out…we had to make a hard register call…like

…Laser::RegisterObject(context);…once we had the template pointer ‘Laser’.

Works perfectly, my objects are all on the queuing cycle!

Lord Fiction