#Are `PackedScene` export variables automatically loaded into memory?

13 messages · Page 1 of 1 (latest)

quartz charm
#

I'm trying pass the resource paths of scenes into a SceneManager script of mine that loads the scene from disc on another thread and displays a loading screen while that happens. To make this less error prone, I'm expecting a PackedScene to be passed into the load method of this script, but I'm wondering if that defeats the purpose of the SceneManager altogether if PackedScene instances already load the scene they reference into memory on startup anyways.

If they do, is there a type that I can use for export variables that contains scene paths which automatically update when project files are restructured? If not, then that's great.

proper wagon
iron relic
#

~~Someone correct me if I'm wrong but loading the PackedScene resource into memory isn't an issue, right?
The instantiating part is what the SceneManagers main purpose is and what takes time and allocates the most memory.

So I think you can just use export variables of type PackedScene directly, unless they are causing a cyclic dependency.~~

#

This will also update their paths automatically if you move or rename them
Edit: I'm stupid

proper wagon
#

if you have a game that is 10 gb big and only use preload/export variables, all those 10 gigs would have to be in memory at the same time.

#

of course instanciating can cause issues if you have to instance a lot at once. but reading from disk is generally much slower than reading from ram.

#

for smaller games i would definetly say to just preload everything. but there is a tipping point where you have to load things dynamically

#

and if you want to make the game easily expandable you pretty much need dynamic loading no matter the size.

quartz charm
quartz charm
#

I ended up creating a Resource class that stores the file path as a string for my levels. This way it can always be updated in one place.

Then I have a scene that I only run when I want to test my project. It loads all those resources from disc and instances the level scenes to make sure that they actually point to valid paths, are unique paths for each LevelData file, and the root nodes have the Level script on them (I couldn't do this with the interface Godot provides for querying scene data of scenes. It only returns the base type of the node, not the type of the attached script.)