HTTP Request _on_request_completed isn't being called when added to main scene

Godot Version

4.4.1

Question

I have the following code, which works when I test the independent scene that it’s in. But once I add this into my main scene and then run the main scene, the _on_request_completed actually never fires. I can’t figure out why…

extends HTTPRequest
@export var base_url: String = "https://someUrl.com/v1"
@export var api_key: String = "someKey"

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	# Connect the request_completed signal
	get_mission_by_lesson_title("Patterns in Two-Way Tables")

func get_mission_by_lesson_title(lesson_title: String):
	# Properly construct the URL with the endpoint and proper URL encoding
	var url = base_url + "/isometric-game?title=" + lesson_title.uri_encode()
	print("Fetching missions with URL:::::", url)
	
	# Headers should be passed directly to the request method
	var headers = ["x-api-key: someKey"]  # Note: space after colon removed
	
	request(url, headers)

func _on_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
	print("FETCHING MISSION::::::")
	var json = JSON.parse_string(body.get_string_from_utf8())
	print("MISSION DATA:::", json)


The issue is that I had a game menu open which paused the main thread for the game >.>

I think I found your issue. You need to connect the request_completed signal to your _on_request_completed function, like so self.request_completed.connect(self._on_request_completed). It looks like you accidentally deleted it on line 6.

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