Godot Version
v4.6.stable.official [89cea1439]
Question
I am trying to make a 3d multiplayer game to learn about how multiplayer works. I tried following a tutorial, but I can’t find a link to it ![]()
The main scene is a Node2D that is being used as a menu. It just has two buttons and is linked to this script:
extends Node2D
var map: String = “res://Maps/YetiBottles/main_game.tscn”
func _on_serverstartbutton_pressed() → void:
HighLevelNetworkHandler.start_server()
get_tree().change_scene_to_file(map)
func _on_clientconnectbutton_pressed() → void:
print(“Client: Client button pressed”)
get_tree().change_scene_to_file(map)
HighLevelNetworkHandler.start_client()
"res:://Maps/YetiBottles/main_game.tscn” has a layout that is:
Node3D
┠╴GamePlatform
┃ ┖╴Ground
┃ ┠╴CollisionShape3D
┃ ┖╴Sprite3D
┠╴Projectile
┃ ┖╴RigidBody3D
┃ ┠╴CollisionShape3D
┃ ┠╴BallDefault
┃ ┖╴HitSoundPlayer
┠╴OmniLight3D
┖╴MultiplayerSpawner
$’Node3D/MultiplayerSpawner’ has its NetworkPlayer set to “res://Player/Player.tscn”, which has the following layout:
PlayerCameraAnchor
┠╴PaddleElevator
┃ ┖╴PaddleBody
┃ ┠╴PlayerCamera
┃ ┃ ┠╴SubViewportContainer
┃ ┃ ┃ ┖╴SubViewport
┃ ┃ ┃ ┖╴MainGameGui
┃ ┃ ┃ ┠╴Control
┃ ┃ ┃ ┖╴ScoreLabel
┃ ┃ ┖╴AimNode_A
┃ ┃ ┖╴AimNode_B
┃ ┃ ┖╴Sprite3D
┃ ┠╴PaddleFixed
┃ ┃ ┖╴Cube
┃ ┠╴CollisionShape3D
┃ ┖╴Unstucker
┃ ┖╴CollisionShape3D
┖╴MultiplayerSynchronizer
The layout is weird because of the WASDEQ movement that it has to support for my game concept. HighLevelNetworkHandler is a Global whose script is:
extends Node
signal host_started()
const PORT: int = 42069 # Below 65535 (16-bit unsigned max value)
const HOST:String = “localhost” # TODO: Add a menu to change this in game.
var peer: ENetMultiplayerPeer
func start_server() → void:
peer = ENetMultiplayerPeer.new()
peer.create_server(PORT)
multiplayer.multiplayer_peer = peer
# Spawn the host player (peer ID 1)
HighLevelNetworkHandler.host_started.emit()
func start_client() → void:
print(“Client: Client starting”)
peer = ENetMultiplayerPeer.new()
print("Client: peer = ",peer)
peer.create_client(HOST, PORT)
multiplayer.multiplayer_peer = peer
I tried making a singleplayer version with the MultiplayerSynchronizer and MultiplayerSpawner gone and with just player.tscn inside the map, and setting the map to the main scene. It worked as intended. I’m not sure why it behaves strangely when trying to make it multiplayer, though that’s probably due to my apparent lack of ability to understand how multiplayer works. Instead of working as intended, the server instance joins the game, spawning as a client, and the Client instance just goes blank.