|Topic was automatically imported from the old Question2Answer platform.
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.
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.
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?
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.
preload doesnt work that way. preload happens on compile time, therefor it only accepts constants.
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.
you dont have to use them right away … have a look
#just load here
my_asset = load("res://thing to load.tscn")
my_other_asset = load("res://other thing to load.tscn")
#instance it here
var thing = my_asset.instance()
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?
This background loading looks like what I have to dive into, thanks for the info.