0 votes

Recently I ran into a problem with my UI-script: There, I add a button and a progressbar to the screen. When the button is pressed, a signal is emitted to another script, wich then runs a function, lets call it "doSomething". Inside this function, a different signal is emitted, to update the progressbar in my UI-script. But this doesn't work at all. Only when the function "doSomething" in the script is finished, it updates the progressbar to 100%. When I print the progress, it shows correct results. Can anybody tell me what to do here?

This is how my code looks:

extends Node

signal doSomething

func _ready():

func _on_main_openMenu():

    var button = Button.new()
    button.connect("pressed", self, "_button_pressed")
    button.anchor_top = 0.5
    button.anchor_left = 0.1

    var progressbar = ProgressBar.new()
    progressbar.anchor_top = 0.5
    progressbar.anchor_left = 0.5

func _button_pressed():

func _on_otherScript_progress(progress):
    self.progressbar.value = int(progress*100)
Godot version 3.4
in Engine by (15 points)

Why don't You show code of this do_somethingfunction and a script of bar, that receives this signal ? ;)

1 Answer

+1 vote
Best answer

You should use threads if you have a function that will take time to complete, and want the main app to remain interactive. What's happening is that the app "freezes" while that long function is running, so it does not render anymore until it's over, at 100%.

If you're loading something like a scene or resource, Godot already has an easy way to do that, check Background loading. Otherwise, you'll have to create your own threads for your behavior, check Using multiple threads

by (286 points)
selected by
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.