Search Unity

Question Multiplayer player mode issue

Discussion in 'Lobby' started by HuginnRaven, Apr 11, 2023.

  1. HuginnRaven

    HuginnRaven

    Joined:
    Dec 20, 2015
    Posts:
    33
    I don't know if this is due to MPPM or not, but I have a sneaking suspicion that it is and just want it confirmed, and hopefully a solution to the issue.

    I'm attempting my first multiplayer game, just small scale prototype at the moment. Found out that 2023 had this really cool thing where you could have multiple players without building the game. Sounds perfect. But I want to test it with Unity Game Services like Relay and Lobby and I can't get it to work.

    Do I need to build it, do I need that build on a separate computer, is there something I can do here?
    I searched the forums, found NOTHING on this. Not surprising considering it's the bleeding edge. But here I am.
     
  2. veleek_unity

    veleek_unity

    Ben Randall Unity Technologies

    Joined:
    Aug 25, 2021
    Posts:
    59
    Like you said, this is pretty burning edge, so there are some issues to be expected. When you say that you can't get it to work can you help clarify what you mean? Are you seeing errors, are you seeing the same user logged in from all the MPPM instances? That will help us narrow down the problem.
     
  3. CoolBeanz7

    CoolBeanz7

    Joined:
    Mar 14, 2022
    Posts:
    18
    The most likely issue is that the players are all using the same authentication ID (aka account). I know there is some code to go around this somewhere in the documentation.

    The quickest way to test without adding any code is to build the project. Run the build and play mode in the editor together, and the build should make its own authentication ID separate from the one the editor is using

    Alternatively, make a button that calls (C#):

    AuthenticationService.Instance.ClearSessionToken()

    and press it on one of the players before authenticating.
     
  4. HuginnRaven

    HuginnRaven

    Joined:
    Dec 20, 2015
    Posts:
    33
    As I suspected.

    Here's the relevant error message, it seems to be that it's the same authentication being sent:
    Outputting
    AuthenticationService.Instance.PlayerId;
    reveals that it is the exact same Player ID being used.

    I'm using anonymous authentication =>
    await AuthenticationService.Instance.SignInAnonymouslyAsync()
     
    Last edited: Apr 11, 2023
  5. HuginnRaven

    HuginnRaven

    Joined:
    Dec 20, 2015
    Posts:
    33
    Ok, I just added this before
    await AuthenticationService.Instance.SignInAnonymouslyAsync()
    and that did the trick completely. Thank you! No more waiting for the build to compile!
     
  6. CoolBeanz7

    CoolBeanz7

    Joined:
    Mar 14, 2022
    Posts:
    18
    I'm happy I could help. Just be careful to remove this for actual distribution of your game if you are running it every time your game authenticates the player, otherwise they will lose their account data every time they sign in!
     
    HuginnRaven likes this.
  7. HuginnRaven

    HuginnRaven

    Joined:
    Dec 20, 2015
    Posts:
    33
    Good call. Thanks!
     
    CoolBeanz7 likes this.
  8. veleek_unity

    veleek_unity

    Ben Randall Unity Technologies

    Joined:
    Aug 25, 2021
    Posts:
    59
    My recommendation is that you add something like #if UNITY_EDITOR around the code block so it'll only be in use when running in the editor.
     
    HuginnRaven likes this.