Creating a UI of list of images - Initializing and showing progress of loading

Godot Version

4.0.3

Question

I’m creating a Control scene that scans a folder containing a lot of images (1000 more or less) and the scene should make a VBoxContainer that contains HBoxContainers, where each HBoxContainercontains a preview of the image, the file name , and a button.
image
The mentioned HBoxContainers in the list of the images are children of the VBoxContainer node that is highlighted and they are instanced scenes.
For example, the node in the orange box:
image
Since I am working with a lot of images, I want to have a progress bar that shows the progress of the initilization of the overall scene, and I don’t want to have a freezing screen.
I’d like to read any suggestions to the specific problem I have.

Edit: Each instanced HBoxContainer has a function that initializes the image, and the name in the preview.

You can use a thread to load the images and everytime a image is loaded you use the call_deferred method to increase your progress bar. This way your main window wont freeze

Well, the steps I see in order to load the whole scene is (For each image in the folder):

  • Create a new instance of a HBoxContainer
  • Load image preview and name to HBoxContainer
    Are you saying that I can do these two steps in a second thread?
    Also, I don’t understand call_deferred

Yes you can load scenes in a second thread. To show the image preview you would have to use the “call_deferred” method, to add your preview from your side-thread to the main-thread. When you use a second thread in your program its not safe to call methods from one thread on the other. You use call_deferred to basically call the method on the other thread after the current frame is done

Thank you! Solved.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.