Hello!
I took the sample project and split it in two, using the same address and connection port. However, I can’t use one of them as a server and the other as a client (the “client project” doesn’t connect to the “server project”, although the client that still exists in the “server project” can connect to its server).
What is the mystery to making this work? To connect clients from on project to the server into another project? GlobalObjectHash must be the same, maybe? How do we edit this hash? And what else?
Thank you very much!
Typically you run the same code base, and you just check for Application.isBatchMode to determine that it is a server. Or, you can simply have a property on a monobehavor like IsServer and check for that. Either way, you will create a Build of your game and decide whether you want the editor to run as a client or a server and the Build EXE runs as whichever too. Typically you will want some kind of main menu or at least a test UI that is the first thing on startup so that you can press a button to make it run as a server or as a client.
If you still want to run two separate projects, most networking libraries don’t handle that very well. Still, the fact that you don’t connect at all seems like another problem entirely. I wouldn’t suggest using two separate projects… but maybe you have some strange requirement.
Just to add to the reply of GetLitGames, a helpful tip is to use the “Server Build” checkmark in the build settings when you’re building so the engine knows it’s your server, sets up the appropriate scripts, and starts in no-graphics mode.
Thank you both for your answers!
Additional question, based on the “Server Build” answer: is there a “Client build option to hide [ServerRPC] code from clients”? My main concern, from the beginning, was not sharing server logic with clients. Sorry if this concern intrinsically doesn’t make sense and I don’t know about it, but thank you very much for clarifying this.
Best Regards!