Skip to content

Instantly share code, notes, and snippets.

@CrankyBunny
Created March 3, 2023 06:03
Show Gist options
  • Save CrankyBunny/71316e7af809d7d4cf5ec6e2369a30b9 to your computer and use it in GitHub Desktop.
Save CrankyBunny/71316e7af809d7d4cf5ec6e2369a30b9 to your computer and use it in GitHub Desktop.
Determine the instance number for Godot run multiple instances feature
var _instance_num := -1
var _instance_socket: TCPServer
func _init() -> void:
if OS.is_debug_build():
_instance_socket = TCPServer.new()
for n in range(0,4):
if _instance_socket.listen(5000 + n) == OK:
_instance_num = n
break
assert(_instance_num >= 0, "Unable to determine instance number. Seems like all TCP ports are in use")
print("We are instance number ", _instance_num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment