Archive 17/01/2023.

App framework befudlement

grokko

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_;

and

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

Modanung

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

context_->RegisterFactory<Laser>();
grokko

Hi,
I believe its registered in the Component class like…
void Laser::RegisterObject(Context* context)
{
cout << "reg here " << endl;
context->RegisterFactory();
}

???

Modanung

Pretty close, it’s a template function=

grokko

i dunno how to do text on this!

vmost

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:

URHO3D_DEFINE_APPLICATION_MAIN(MyApp)
grokko

i did that. the class is in the website

Modanung

I dunno what you mean by that. :slightly_smiling_face:

Modanung

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.

vmost

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?

Modanung

:musical_note: Too Many People by Leaves

grokko

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…

vmost

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
grokko

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