I have the following code:
this->GetContext()->RegisterSubsystem< Player >();
this->GetContext()->RegisterFactory< PlayerComponent >();
this->GetSubsystem< Player >()->Start();
void Player::Start( void ) {
...
auto* level = this->GetSubsystem< Level >();
this->player_ = level->getScene()->CreateChild( "Player" );
this->player_->CreateComponent< PlayerComponent >();
...
}
auto* playerComponent = this->GetSubsystem< Player >()->GetComponent< PlayerComponent >();
if ( input->GetKeyDown( Urho3D::KEY_W ) )
playerComponent->MoveX( 1 );
if ( input->GetKeyDown( Urho3D::KEY_S ) )
playerComponent->MoveX( -1 );
if ( input->GetKeyDown( Urho3D::KEY_A ) )
playerComponent->MoveZ( 1 );
if ( input->GetKeyDown( Urho3D::KEY_D ) )
playerComponent->MoveZ( -1 );
void PlayerComponent::MoveX( const float x ) {
std::cout << this << std::endl;
};
When I call playerComponent->MoveX()
I get 0
. It seems the PlayerComponent
component is never being initialized.
The full code is on GitHub.