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

Situation:
I have a (possibly large) number of levels, in each level the designer can set a title, subtitle and other script parameters that define the gameplay of that specific level.
I prefer to have it there as script variables so that a designer can change it directly without having to modify the script itself.

Task:
I want to create a 'Level select' page where i use some of those script parameters in the list entry of each level.

Question:
HOW can i access those script parameters without actually loading the level completely?

I understand that i can just preload and instantiate every single scene, at which point i could call a function in the scene's script that would transfer the necessary data to a global variable, but i guess that would waste a lot of memory / computation to loop through all the levels?
Especially when i might have hundreds?

TL;DR;
Is there a way to access a scene file's export parameter without 'loading' it completely into memory / what's the most efficient way to do this for hundreds of files?

in Engine by (59 points)

I will go with the load packedScene option for now, but i am not sure if this would work for hundreds of scenes.

So if someone could point out exactly if this would be good for hundreds of items?!

In the future i will probably just keep using the packedScene option but execute it only after the first installation or some update of level files and store the parsed data in an extra file, so that the parsing itself won't happen on every startup...

1 Answer

+5 votes

You can avoid instancing by using state of PackedScene, like this:

extends Node

onready var BahScn = preload("res://Bah.tscn")

func _ready():
    var state = BahScn.get_state()

    for idx in range(0, state.get_node_count() ):
        for propIdx in range(0, state.get_node_property_count(idx) ):
            var pname = state.get_node_property_name(idx, propIdx)
            var pvalue = state.get_node_property_value(idx, propIdx)

            print ( pname + " = " + str(pvalue) )

It prints this for me:

script = [GDScript:1077]
exportedString = valueOfExportedString

There's my exported variable with its value.

by (2,308 points)

It looks like the loading does indeed not need much resources, so i will go with this for now, but i'd love to hear someone explain better IF and WHY this is ok and not a big performance problem if done for hundreds of files...

Did you considered using a thread(s) for this task? It could start processing files as soon as application is launched.

If you're new to Godot threads, check out official sample project:
https://godotengine.org/asset-library/asset/144

That is a good idea, but as i want to deploy on mobile i need to keep the resource usage as low as possible.

I actually made a test where i parsed 11 level files a hundred times, and even so the garbage collection and caching kept the memory to a minimum (which might not be the case if it were 1100 different levels) it took one full minute on my desktop pc to parse all the files.

So i think that i will go with the plain file parsing now, the tscn files are very simple and easy to parse.

I am testing the performance right now...

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.