+1 vote

hello every one. in the game I'm making I have ran into a big problem.
in the code I have it so when you enter an area you go to a scene. and when your done with the scene you go back to the level. but when you do it is super slowed down or frozen
is there a way to fix it in the code or is it just something wrong with my cumputer

Godot version 3.3.2
in Engine by (32 points)

1 Answer

+1 vote

I believe what you are running into the time it takes to load a new scene (mostly around loading textures into video memory). The general issue here is that when you are loading between scenes it will unload textures(images) that are not being used from memory. Then if you need those textures again in another scene it will reload them.

There are a lot of variables in this, but first thing you can test is to build the game and test the release version. The debug and or editor runtime can be significantly slower at running load times because of how debug works. If it runs in release mode in a reasonable time frame then you might not have to optimize or change anything. Other than that there are few ways you can handle these issues.

  1. Create a loading screen in-between loading times so that you can have the down-time necessary to load between scenes of whatever size. This is the simplest solution, I will link some background interactive loading from Godot-stable page below.
    Background Loading Godot- Stable

  2. You can preload the images used by your game and store them in a global(Singleton class, i.e. Autoload.) This works because in a global state if these are loaded into a class variable that will never be deleted(hence the global class), the textures will be in video memory from the time you load them up, till your game closes. From this class you can load up images one time and just store them until the game closes. When you need to get one you just pull it from the array.

  3. The most complex one is to create some sort of loading manager that handles loading the images when you will need them. Such as preloading the images right before the level starts, and preloading the main scene back before you finish the level. This obviously will require a lot more work to time everything as required.

Hope this helps

by (162 points)

thanks for the advice but none of these seam to work. now in the loading screen is the one thats frozen. and the singoltin makes it so that my level scene is in every scene

Sorry to hear that, It's hard to know what is going on without code, but keep trying. The singleton class is suppose to load up specific images, not the whole scene at once. So you would load up the images you would need for a level. Then when you load that level, you use those preloaded images in that level when it is created or whenever those images are used anywhere in your game. It's like preloading all textures you would use in a game, then just using them when you need them programmatically.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.