UPNP not working, get_gateway() failing

Godot Version

Godot 4.2


func upnp_setup():
	var upnp = UPNP.new()
	var discover_result = upnp.discover()
	assert(discover_result == UPNP.UPNP_RESULT_SUCCESS, \
		"UPNP Discover Failed! Error %s" % discover_result)
	assert(upnp.get_gateway(), \
		"UPNP Invalid Gateway!")

	var map_result = upnp.add_port_mapping(PORT)
	assert(map_result == UPNP.UPNP_RESULT_SUCCESS, \
		"UPNP Port Mapping Failed! Error %s" % map_result)
	print("Success! Join Address: %s" % upnp.query_external_address())

The code works fine up until get_gateway() and I have no clue why. Someone help I do not know what I am doing.

Same code works for me. I’d guess your router or network setup doesn’t like it. What do you get from get_device_count() ? And for each of those devices what does igd_status say?

1 Like

It only came up with one device, and I’m not sure how to use igd_status :confused:

I dont know if this helps but the game stops running whenever i try to close it

How do i run igd_status?


im sorry im desperate :frowning:

Try it on a different network at a friend’s house or something and it will probably work. Upnp support is flaky on a lot of routers.

Upnp isn’t a real solution anyway. Maybe if you are working on something just for yourself but it doesn’t work for the general public. ISP’s generally implement CGNAT these days which means port forwarding doesn’t work. You’ll need something else, dedicated servers, UDP hole punching etc.

I opened an issue about this last week when I ran into the same problem:

But yeah, I quickly found out that UPNP is not what most games use anyway.