Godot Version
4.6
Question
I was wondering if it’d be appropriate to split my server and client scripts into two, as I feel it would de-clutter everything if it were separate? I’m not sure whether this is the common way to approach it though. I cannot think of any functions that I would have to duplicate or that would make it any more difficult to work with if I did.
I did try going about this, but I can unfortunately not figure out how to send RPCs from one script to another on C#? (or GDscript for that matter but I’m not using it at the moment)
Thanks for your input
In a typical Client/Server architecture, this is how you would do it. However you cannot use @RPCs that way. It is not how they are designed. So you have two options:
- Code your own networking protocol or use an addon that does it for you.
- Split the code by exporting the server as headless. Godot export is pretty good at excluding unneeded files from an export. Let it handle it.
3 Likes
Thanks for your reply, unfortunate that it doesn’t work natively. So, do people just put all networking into one script? I can imagine that getting messy quite quickly.
Regarding your first point, I wouldn’t opposite it but I can also imagine there not being much to any documentation on how to go about this online I presume.
It’s important to understand that making a networked game is a whole order of magnitude more difficult than making a single-player game. It’s hard even for those of us with networking expereince.
No. You kinda have to build a networked game to understand how to use it in my experience. There are nodes you can use to sync nodes, as well as @RPC calls. It’s honestly really hard to have the networking separate from the rest of your code.
There are tutorials. And the Godot docs are a good place to start. But ultimately, it’s going to require you to read how game networking works and do it yourself. Or you can try something like NetFox, for which someone made a NetFox Godot Plugin.
1 Like
I see. I did try sending RPCs in another script than the one where the server/client session was first started and it seemed to work fine so long as the RPC call and the function it was calling weren’t located in two separate scripts. I’m assuming that should be fine to do, have RPC signals and functions in other scripts so long as I keep it organized?
I apologize for the many questions. Still trying to learn about networking.
Yeah you can have @RPC calls in multiple scripts, and call them from anywhere. But that does not mean you should have a central NetworkManager handling everything. Instead, you would be better served using an OOP (Object-Oriented Programming) approach and encapsulating the code for an object inside it.