Hi,
I just had a few questions about how to use custom game servers and Unity.
Is the Unity client meant to use UNET to connect to the provided IP+Port?
How then are messages handled?
I can't see in the GameserverSDK anywhere how to listen/handle messages sent from players.
Likewise, how does Unity listen for messages from the server?
Thanks!
Thanks!
So regardless of what the server is coded in- for a Unity game, to connect to a hosted server instance on PF, it has to use UNET/Mirror to connect to the IP directly?
What about messaging? How does a client send a message to the server, with the server then sending messages to all players?
@Sim Basically, however you set up your server (I'd recommend reading the Getting Started Guide for Mirror to get acquainted with how Unity servers work), you don't even really need to consider PlayFab or hosting or any of that until you have a client/server and can connect them both.
Here's an example of how we'd set up a simple client/server architecture using UNET or Mirror (there are many ways to do networking in Unity, but this is what we use):
ExampleScript.cs:
//commands are called on the server [Command] public void CmdAddPlayerItem (Player player, Item newItem) { player.AddItem(newItem); } //rpcs are called on clients, target rpcs are only called on specific (target) clients [TargetRpc] public void TargetUpdateScore (NetworkConnection connection, int newScore) { this.score = newScore; } //on the client: void ClickOnItem(Item clickedItem) { CmdAddPlayerItem(this, clickedItem); } //on the server: void UpdateClientScore(int score) { TargetUpdateScore(connectionToClient, score); }
The main point is, once you can connect your client to your server with an IP and Port, then you can host it on PlayFab and connect to it
Answer by Brandon Phillips · Jul 10, 2019 at 12:21 AM
You can create your server however you want. With Unity, the easiest solution is probably using UNET (although I'd recommend Mirror since it's basically an up-to-date/maintained fork of UNET). We use Mirror/UNET, and simply have our PlayFab-hosted server running our game in server mode, and the GSDK just tells PF that the server is active/players are connected.
We use PF Matchmaking in the client to get the IP/Port, then connect our client using those connection details to the server. If you use Unity/UNET/Mirror/etc to create a game that can be both a server and a client, and can connect to the server instance from the client, you can host your server with PF.
If you have any more questions, feel free to ask because I've spent hours and hours figuring a lot of this Unity-specific stuff out (when it comes to PlayFab), so I can probably help with a lot of the questions you might have.
Hi Brandon. Could I take you up on that offer of asking more questions? Going mad over here :)
Sure! Feel free to give me an email (brandon@uprootstudios.com) or on Discord/Slack if that's easier for you