Extra Room Node on reload
HeiMao808 opened this issue · 9 comments
So this is a very odd bug(?) that I am running into. When my player dies anywhere on my map (so far) the game will respawn it normally WITH THE EXCEPTION of this one combination of circumstances.
In the image above I have "S" marked as where the player's last save point is. When the player dies in the circled room they are not placed directly at the save point, but rather 2 room blocks up. On top of this, I get an additional node instance of the same room that ends up persisting when I change rooms.
I haven't got a clue why this is happening, but is there a way I can stop this extra child node?
Here is my kill function in my player as a reference. I don't believe I have changed any code that involves loading rooms.
func kill():
if currentHealth <= 0:
print("You Died")
currentHealth = MaxHealth
is_dead = false
Game.get_singleton().reload_game()
else:
print("You Fell")
currentHealth -= 1
position = SafePosition.global_position
Looks like your player respawns outside the room, so the room loads and immediately transitions. As for double node, I'm not sure what causes it, but I observed it a few times with lava room in the example project. I was not able to reproduce it reliably.
I did recall the lava room being duplicated when I was trying the project out. I am able to reproduce the lava room dupe reliably. Simply dying in the lava causes the extra room nodes to appear. This is on a fresh copy of the master.
Ok so the room always duplicates, but I not always noticed it, because the duplicate was exactly at the position of the original. I'll look into it.
Fixed the sample project in 725b96c
Looks like some physics bug, the player was repeatedly entering lava (despite being teleported away after first collision) and loaded the map again before it finished loading.
Check if it's fixed in your project too.
Looks like your new room did not load for some reason? Or it doesn't have RoomInstance. But it should break any transition, not only restart, so idk what is happening.
If you are able to share the project I can take a look.
I tried making a repo, it's been a while... Added you as a collaborator.
You could've just sent me ZIP in a DM or something.
I'm not sure if it's an issue I can fix in the plugin. It's problem with your restart_game()
. You are loading a map and teleporting the player at the same time. Game frees the map, MetSys loads a map (it's independent from Game), but the previous instance is invalid (because you are in the middle of transition). I tried setting instance to null and it results in a glitch.
You can fix it on your side by awaiting room_loaded
.
func reload_game():
var save_manager := SaveManager.new()
save_manager.load_from_text(SAVE_PATH)
load_room(save_manager.get_value("current_room"))
await room_loaded
player.position = save_manager.get_value("save_position")
Thanks, it's working!