fix: errors when loading levels due to gamemodes
parent
e2d56ed6d4
commit
cb6fd87e72
|
@ -120,7 +120,7 @@ Level3D *GameRoot3D::load_level_at(gd::Ref<gd::PackedScene> level, gd::Transform
|
||||||
// store and add to tree at desired transform
|
// 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 is the first level containing a game mode currently active use it's gamemode as a prototype
|
||||||
gd::Ref<gd::PackedScene> game_mode_prototype{instance->get_game_mode_prototype()};
|
gd::Ref<gd::PackedScene> game_mode_prototype{instance->get_game_mode_prototype()};
|
||||||
bool const switch_game_mode{!this->game_mode || (this->game_mode == nullptr) != game_mode_prototype.is_null() || this->game_mode->get_scene_file_path() != game_mode_prototype->get_path()};
|
bool const switch_game_mode{!this->game_mode || !game_mode_prototype.is_valid() || this->game_mode->get_scene_file_path() != game_mode_prototype->get_path()};
|
||||||
if(switch_game_mode) {
|
if(switch_game_mode) {
|
||||||
this->set_game_mode(instance->get_game_mode_prototype());
|
this->set_game_mode(instance->get_game_mode_prototype());
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,6 @@ void GameRoot3D::unload_all_levels() {
|
||||||
for(gd::KeyValue<gd::StringName, Level3D*> &kvp : levels)
|
for(gd::KeyValue<gd::StringName, Level3D*> &kvp : levels)
|
||||||
kvp.value->call_deferred("queue_free");
|
kvp.value->call_deferred("queue_free");
|
||||||
this->levels.clear();
|
this->levels.clear();
|
||||||
this->spawn_points.clear();
|
|
||||||
this->reset_game_mode();
|
this->reset_game_mode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,8 +181,10 @@ void GameRoot3D::set_game_mode(gd::Ref<gd::PackedScene> prototype) {
|
||||||
this->remove_all_players();
|
this->remove_all_players();
|
||||||
if(this->game_mode != nullptr)
|
if(this->game_mode != nullptr)
|
||||||
this->game_mode->queue_free();
|
this->game_mode->queue_free();
|
||||||
if(prototype.is_null() || !prototype.is_valid())
|
if(prototype.is_null() || !prototype.is_valid()) {
|
||||||
|
this->game_mode = nullptr;
|
||||||
return; // allow "unsetting" the gamemode by passing an invalid gamemode
|
return; // allow "unsetting" the gamemode by passing an invalid gamemode
|
||||||
|
}
|
||||||
// Detect passing of valid scene that is an invalid game mode
|
// Detect passing of valid scene that is an invalid game mode
|
||||||
if(!gd::ClassDB::is_parent_class(prototype->get_state()->get_node_type(0), "GameMode")) {
|
if(!gd::ClassDB::is_parent_class(prototype->get_state()->get_node_type(0), "GameMode")) {
|
||||||
gd::UtilityFunctions::push_error("Attempted to load non-gamemode scene as gamemode");
|
gd::UtilityFunctions::push_error("Attempted to load non-gamemode scene as gamemode");
|
||||||
|
|
Loading…
Reference in New Issue