Wierd frame drops

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 09makri

When I first play my game it all works fine but as soon as I Reload the current scene because only one player is left on the screen the frame drops to 1-4fps and when using “print(OS.get_static_memory_peak_usage())” on the ready function after reloading I get this: “31118420” code repeating over and over. :confused: I’m kinda stuck

:bust_in_silhouette: Reply From: Moldor2

Could you provide your code for reloading the scene?

this is the code for the section in question:

func _process(delta):
if get_tree().get_nodes_in_group(“Player”).size() == 1:
get_tree().reload_current_scene()

09makri | 2020-09-24 14:26

:bust_in_silhouette: Reply From: Zylann

Hard to know how to help here without much details.

Maybe just this:

when using “print(OS.getstaticmemorypeakusage())” on the ready function after reloading I get this: “31118420” code repeating over and over

31 Mb is not much. Your problem might be CPU or GPU.

You say you put the print in _ready, but if it spams, it probably means you are reloading your scene every frame, which could explain the low FPS. Check the code where you reload the scene and make sure it gets called only once when needed.

ah, Mabey I should move the reload scene to its own autoloaded script instead of in the “world” node?

func _ready():
print(OS.get_static_memory_peak_usage())

func _process(delta):
if get_tree().get_nodes_in_group(“Player”).size() == 1:
get_tree().reload_current_scene()

09makri | 2020-09-24 14:27

Making things an autoload doesn’t necessarily fix things. You have to figure out in your game if it’s getting reloaded every frame. If it is, find out why by looking at the code, using breakpoints, and fix it.

IF it IS reloaded every frame, based on the code you posted, it means that after the scene reloads there is STILL only one player in the scene. You may have to debug this.

Zylann | 2020-09-24 14:35

so I think I know what’s happening

I set it up like this:

var players

func _physics_process(delta):
players = get_tree().get_nodes_in_group(“Player”).size()
print(var2str(players))


when the game starts the print shows 2 like expected but when I reload the scene it prints NULL, could this be about the groups and needing to re-add the players to the “Player” group

09makri | 2020-09-24 15:53