The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

I have assets that I want to be ready for use in my game, but not necessarily a part of any tree yet. I have a problem with load, because it causes a lot of lag when it's dynamically loading an asset in for the first time.

  1. Is there a way to reference a string constant from another script for preload? When I try it, Godot's preload doesn't accept it. I'm assuming because that very action is dynamic in nature.

  2. I need to reference a big library of potential assets depending on the players choices prior to using the script I want to use preload in. I'd like to have that list in a separate script or at least a dictionary to reference. Is this possible?

  3. How can I have the assets I need preload in without necessarily using them right away?

This loading lag during the gameplay on the android is killer.

Godot version 3.3
in Engine by (367 points)

1 Answer

0 votes
Best answer

Hi.
preload doesnt work that way. preload happens on compile time, therefor it only accepts constants.

question 1
... no

question 2:
you cannot use preload for this. You dont have to have a list in another script. Just write youself a function to initialize this class. Then load your assets before the "action" starts.

question 3:
you dont have to use them right away ... have a look

extends BaseClass

var my_asset
var my_other_asset

func load_assets():
    #just load here
    my_asset = load("res://thing to load.tscn")
    my_other_asset = load("res://other thing to load.tscn")

func use_asset():
    #instance it here
    var thing = my_asset.instance()
    thing.do_stuff()
by (4,088 points)
selected by

Thanks for replying.

I've done exactly the type of loading situation you're showing in your example. The problem I'm having is on the mobile version of the game is; I get a lot of lag every time the instance loads up the first time during the gameplay because it's loading in that asset dynamically for the first time at the moment it's called and added to the scene.

I want it to be preloaded at compile time for this particular scene so that it doesn't need to load it during the gameplay

I would like to mitigate that lag entirely using preload. Essentially having the instances loaded at compile time.

Any pointers on achieving this?

You cant!

It doesnt work that way!

Maybe this can help you
https://docs.godotengine.org/en/stable/tutorials/io/background_loading.html

But i think you have to rethink your program flow.

This background loading looks like what I have to dive into, thanks for the info.

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 Frequently asked questions and 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 [email protected] with your username.