question

k-krrs avatar image
k-krrs asked

Multiplayer with authoritative server hosted by PlayFab with Unity Networking

The documentation is very vague on this subject, and I'm an absolute beginner with networking. I don't know where to start with something like this. Basically what I need is to have a server which takes inputs, simulates a game and sends back transforms to all clients. How can I do this with PlayFab and Unity networking? I'm having a hard time figuring out how PlayFab and UNet will work together. What do I need to do, as in what needs to be included in the build on PlayFab, how to connect to it etc.?

Custom Game Serversdocumentation
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andy avatar image
Andy answered

<Posting a new answer as I was running against the character limit>

Great! I can't comment on exactly how it would work in Unity's Network Manager, but I can explain how the PlayFab side of things works. For now, I'm going to assume you're using PlayFab's server hosting and matchmaking.


When we determine that a new server instance needs to be started, we push your exe onto a VM and then start it via a command line. You have a lot of leeway in how you define this command line, but our example looks like this:

-game_id=<game_id>
-game_build_version=<game_build_version>
-game_mode=<game_mode>
-server_host_domain=<server_host_domain>
-server_host_port=<server_host_port>
-server_host_region=<server_host_region>
-playfab_api_endpoint=<playfab_api_endpoint>
-title_secret_key=<title_secret_key>
-custom_data=<custom_data>
-log_file_path=<log_file_path>
-output_files_directory_path=<output_files_directory_path>
-batchmode

Notice that we're telling you the host domain and port that you should start listening on. You'll need to figure out how to take those parameters and provide them to your networking layer.

Additionally, once your server instance is up and running, you can register it for Matchmaking by calling our RegisterGame API. You'll also want to send out a heartbeat and deregister once you have things working.

This is all explained in greater detail in the tutorial I linked earlier: https://api.playfab.com/docs/tutorials/landing-tournaments/multiplayer-servers.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

k-krrs avatar image k-krrs commented ·

What data types are each of the command line parameters? Or do I just take them as strings?

0 Likes 0 ·
Andy avatar image Andy ♦♦ k-krrs commented ·

I'd recommend treating them as strings.

0 Likes 0 ·
k-krrs avatar image k-krrs commented ·

Also I am confused as to whether I need to call Register/DeregisterGame and a Heartbeat if I'm using PlayFab's hosting and PlayFab's matchmaker.

0 Likes 0 ·
Andy avatar image Andy ♦♦ k-krrs commented ·

You should still call register and deregister, but heartbeat isn't necessary.

0 Likes 0 ·
Andy avatar image Andy ♦♦ Andy ♦♦ commented ·

Scratch that. I was mistaken. None of the register, deregister, and heartbeat calls are needed when using PlayFab hosting.

0 Likes 0 ·
Andy avatar image
Andy answered

Honestly, the first thing I would focus on is getting your server working and clients connecting to it without thinking about hosting or PlayFab at all. That will get you to the start of this guide here: https://api.playfab.com/docs/tutorials/landing-tournaments/multiplayer-servers.

Once you've got a functional dedicated server, then you can start thinking about things like discovery, matchmaking, and hosting. That is where PlayFab can offer solutions to help your game run at scale. As you start to dig into that later class of problems, I'm happy to answer questions you come across.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

k-krrs avatar image k-krrs commented ·

I already created a functional server (somewhat - only allows movement right now) and since I'm using Unity's Network Manager I'm not sure how the server will know when I upload it on what IP to use. Currently I connect via localhost:7777 but that needs to be set in the editor. How will the server set it to use its own port and its own IP?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.