Godot Version
4.3
Background
So, I’m still refactoring my netcode, but I’ve made considerable progress. Before I ask my question, I need to detail how my codebase works.
So I’m developing a multiplayer, PvP, third-person shooter that uses a dedicated server architecture.
The project operates like this:
- Game Boots (with or without the “dedicated_server” feature from the export presets)
- The main scene loads. It contains the game world, network manager(s), all players, and more.
- The
network_check
script runs in the NetworkCheck node. This node checks if the project has the “dedicated_server” feature. Deletes the opposite network manager and renames the surviving manager’s node to a genericNetworkManager
in order for the client and server to communicate with one another. Lastly, it deletes itself to save memory. (I have this in place so I can develop from one project. It’s much easier than having 2 separate ones)
func _ready() -> void:
#INFO If the file is a dedicated server:
if OS.has_feature("dedicated_server"):
delete_for_server()
delete_self()
#INFO If the file isn't a dedicated server:
else:
delete_for_client()
delete_self()
---------------------------------------------------------
func delete_for_server() -> void:
Client_Manager.queue_free()
Server_Manager.name = "NetworkManager"
func delete_for_client() -> void:
Server_Manager.queue_free()
Client_Manager.name = "NetworkManager"
func delete_self() -> void:
queue_free()
- Once this is done, the server will create itself (at localhost for testing) and the client(s) will automatically join (for testing).
Now the client can send an rpc_id(1)
to the server and vice versa at any time to communicate.
Intention
What I want for this system is the following:
- Client sends input data via their network manager.
- Server receives that input data and queues it for the next network tick.
- The network tick happens, making the server’s network manager trigger a client network manager RPC that connects to their player script. (This is the issue)
- The client’s player script then performs that action.
Question
How do I communicate between the client’s network manager and the client’s local player script?
I’ve tried and consider some options already (Some of these could still work, but I’m not sure):
- I tried using signals, as the client’s player script is local. Meaning I can use the RPC chains to lead back to it.
The issue I’ve encountered was trying to connect the signal. Since the client’s manager node’s original name is ClientManager
, that then gets changed to NetworkManager
, it makes it so the player script can’t find the node needed for a signal connection or the .connect
keyword is invalid.
Connecting the signal the other way around has the same issue. The player’s node name is their multiplayer ID. (This is required to identify players for loading, unloading, and more)
This method can still work. It might be due to when the player script is loaded (after the server detects a client joined).
- I considered using server RPCs. But that doesn’t work, as the player node’s name needs to be their ID and I still don’t have the client connected to their player as well.
I could use some help untangling the logic of this issue. Any suggestions are very appreciated.