Game freezes when some scene is added (instanced) only the first time. How I solve it?

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

The problem is quite simple: I make the classic scheme of adding a scene with instance and everything normal, except that the first time the new scene appears, the game freezes a lil. And it’s only the first time the scene is instanced.

Imagine this: I make a instanced scene that is a shot and this shot will appear several times in the game, even if it disappears from the screen after a while (with “queue_free”), only first time it appears is that the freeze problem occurs.

How can I solve it?

Tks guys

:bust_in_silhouette: Reply From: gmaps

Just had the same problem, and fixed it by using preload function:

var my_scene= preload("res://scenes/MyScene.tscn")

If you use “load” function just replace it with “preload”. Load is lazy fetching, it fetches the resource when it appears. Preload is eager - it does it at the start.

solved; you are my hero

lucasfazzi | 2019-10-11 18:32