Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Sim · Jul 09, 2019 at 11:19 PM · unity3dMatchmakingCustom Game Servers

Confused about server setup - C# Custom Server, Unity Client

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!

Comment

People who like this

0 Show 2
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sim · Jul 10, 2019 at 07:19 AM 0
Share

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?

avatar image Brandon Phillips Sim · Jul 10, 2019 at 03:59 PM 1
Share

@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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

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.

Comment

People who like this

0 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Andrew Lower · Jan 19, 2021 at 09:24 AM 0
Share

Hi Brandon. Could I take you up on that offer of asking more questions? Going mad over here :)

avatar image Brandon Phillips Andrew Lower · Jan 19, 2021 at 09:54 AM 1
Share

@Andrew Lower

Sure! Feel free to give me an email (brandon@uprootstudios.com) or on Discord/Slack if that's easier for you

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    6 People are following this question.

    avatar image avatar image avatar image avatar image avatar image avatar image

    Related Questions

    Custom game server instance (unity) does not start 1 Answer

    Cannot start my custom server from the PlayFabClientAPI,Сannot start my custom server from the PlayFabClientAPI 1 Answer

    How to redeem matchmaking ticket in Thunderhead and Matchmaker (Preview)? 1 Answer

    How do I find the fields to input into RedeemMatchmakerTicket in UE4? 1 Answer

    PlayFab Matchmaking with custom game servers 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges