diff --git a/game_root.cpp b/game_root.cpp index 8a803ae..163d5ad 100644 --- a/game_root.cpp +++ b/game_root.cpp @@ -83,9 +83,9 @@ bool GameRoot::initialize_player(IPlayer *player, uint32_t id) { found.second = player; // set player id player->player_id = id; + this->emit_signal("player_spawned", player->to_node()); this->add_child(player->to_node()); player->setup_player_input(found.first); - this->emit_signal("player_spawned", player->to_node()); return true; } @@ -124,7 +124,8 @@ void GameRoot::set_game_mode(Ref prototype) { // allow "unsetting" the gamemode by passing an invalid gamemode // shorthand for this behaviour is reset_game_mode if(prototype.is_null() || !prototype.is_valid()) { - this->game_mode->_end(); + if(!this->game_mode.is_null() && this->game_mode.is_valid()) + this->game_mode->_end(); this->game_mode.unref(); return; } @@ -181,14 +182,14 @@ Level3D *GameRoot3D::load_level_at(Ref level, Transform3D at) { UtilityFunctions::push_error("Unexpected failure to instantiate level scene '", level->get_path(), "'."); return nullptr; } - // store and add to tree at desired transform - this->add_child(instance); - instance->set_global_transform(at); this->levels.insert(level->get_path(), instance); + // store and add to tree at desired transform // if this is the first level containing a game mode currently active use it's gamemode as a prototype if(this->game_mode.is_null()) { this->set_game_mode(instance->get_game_mode_prototype()); } + this->add_child(instance); + instance->set_global_transform(at); return instance; }