0 votes

In the official documentation there is an example on how to use this class. Part of the example contains this code:

# Wait until resolved and connected
while http.get_status() == HTTPClient.STATUS_CONNECTING or http.get_status() == HTTPClient.STATUS_RESOLVING:

However when I export such code to HTML5 and run it in a browser, I get the following error message in the Godot debugging console:

HTTPClient pooled multiple times in one frame, but request cannot progress more than once per frame on the HTML5 platform.

Further investigation allowed me to find that I should wait for frames instead of doing a delay, using this code:

yield(get_tree(), "idle_frame") 

But this is not always possible, especially when the script is in a utility class that isn't meant to be added in a scene, thus is an Object and not a Node.

What's the best strategy in such case?
I see that I can refactor my whole utility class to become a Node and add it to the scene just to have access to the SceneTree so I can wait for a frame, but it breaks the whole architecture and it makes dirty code, which I really want to avoid.

in Engine by (697 points)

2 Answers

0 votes


I used last time HttpClient. Yes, in case of HTML5, you have to send one poll per frame, so I've created a Node, which is in the tree and replace all OS.delay to yield.

In place of HttpClient you may use HttpRequest node, which use HttpClient internally

by (164 points)
0 votes

The scene tree is the main loop, so use

yield(Engine.get_main_loop(), 'idle_frame')

instead of yield(get_tree(), 'idle_frame').

by (1,080 points)
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 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 webmaster@godotengine.org with your username.