This serves as a breakdown of this multiplayer template used for a Godot 4.6 project to quickly crash course Godot P2P ENet multiplayer. The template consists of the following features:

  • A lobby menu where a LAN player can host
  • A player controller
  • An inventory
  • And a global chat interface

Notably, we’re concerned about the networking part of this project such as establishing a connection, replicating player positions on each client, and determining multiplayer authority. The following diagram breaks the project down in slightly more detail, but most of our networking components ultimately lies in:

  • The player controller player.gd
    • In this case, the script is not just a player controller but a general representation of the client/peer, so it also has some multiplayer logic like chat or setting player skin
  • The chat interface
  • The network.gd singleton
---
title: Project Structure
---
flowchart LR
	Globals((GLOBAL
	Item Database))
	Globals2((GLOBAL
	Network))
    Level.tscn(Level.tscn
    Main Scene) --> UI
    Level.tscn --> PlayersContainer
    Level.tscn --> level(Static Level
    i.e. Floor, Lighting)
    UI --> Inventory
    UI --> Chat
    UI --> main(Main Menu)
    PlayersContainer --> player1(Player Instance 1)
    PlayersContainer --> player2(Player Instance n...)
    player1 --> Collision
    player1 --> SpringArm
    player1 --> PlayerLabel
    player1 --> 3DRobot
    player1 --> MultiplayerSynchronizer
    3DRobot --> Skeleton
    3DRobot --> tree(AnimationPlayer
	& AnimationTree)
	
    style Inventory fill:#FFA500
    style UI fill:#FFA500
    style Chat fill:#FFA500
    style main fill:#FFA500
    style Globals fill:#ADD8E6
    style Globals2 fill:#ADD8E6
    style Level.tscn fill:#ADD8E6
    style level fill:#C4A484
    

Before we begin, let’s take a look at the things we might come across related to multiplayer without worrying about them yet:

  • There is a MultiplayerSynchronizer node on the Player node.
  • player.gd has an @rpc annotation on functions related to inventory, changing name, changing skin.
  • All of the initial multiplayer setup is done in network.gd which initializes a ENetMultiplayerPeer, hooks into signals like peer_connected/connected_to_server, and provides helpers like join_game.
  • These components can access a globally available multiplayer keyword from the MultiplayerAPI.