Search Unity

Multiplayer Usernames Problem

Discussion in 'Scripting' started by Doomer022, Jul 6, 2018.

  1. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    I know I post a lot of questions about this topic, and in general, but sometimes i just want to hear what other people say about the problem :)

    Okay, So I was happily working on this multiplayer game again. The previously asked Login Menu now works flawlessly, but there is one BIG problem. You enter your name, you join the lobby, you see the 3D Text Mesh showing your name. Its just awesome. HOWEVER, all the other players have the standard "Username" Nametag on them. People on the server only see their own name, everyone else is just "Username". How can I fix this issue?

    Here is the script Im using, both the script for the Login menu and for the Lobby.

    Login Menu:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class LoginMenu : MonoBehaviour {
    8.  
    9.     public InputField nameField;
    10.     public Button applyButton;
    11.     public static string userName;
    12.  
    13.     void Start () {
    14.         nameField.characterLimit = 20;
    15.         userName = "Player";
    16.     }
    17.  
    18.     public void OnButtonClick () {
    19.         userName = nameField.text.ToString();
    20.         SceneManager.LoadScene(1);
    21.     }
    22. }
    23.  
    Lobby script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class PlayerLoginNameGet : NetworkBehaviour {
    7.  
    8.     public TextMesh nameMesh;
    9.  
    10.     [SyncVar]
    11.     public string lobbyName;
    12.  
    13.     void Start ()
    14.     {
    15.         if (isLocalPlayer)
    16.         {
    17.             lobbyName = LoginMenu.userName;
    18.             nameMesh.text = lobbyName;
    19.         }
    20.     }
    21.     void Update ()
    22.     {
    23.      
    24.     }
    25. }
    There is also a script for the game match, but its literally the same as the lobby one. Hopy I could help, and so can you! :)

    I am making this same thread now for the second time, hopefully someone can give me an answer now :p
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Hi GVT017, writing networked games is tricky and something that doesn't easily lend itself to simple trial and error to learn. So, if I may, I will make one suggestion and ask one question. :)

    My suggestion: do not use UNET. It is discontinued (unsupported), awkward to use (I had to code in many workarounds whilst trying to use it) and ultimately has a showstopper bug if you want to have post-game scenes.

    My question: have you already followed some tutorials right through to get a basic understanding of how to write a networked game?
     
  3. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    Yeah, I did. And what should I use instead of UNet? I mean, I have no problems with it. Yeah it really tricky to get stuff working. What do you suggest then?

    Also, Is there any way I can fix this username issue? Because so far, everyone was trying to steer me away from UNet, I dont care what I have to use, I just want it to work. Nothing more or less. So, anysuggestions about the username issue and about what should I use instead of UNet then? :-/
     
    Last edited: Jul 6, 2018
  4. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    For my personal opinion, I'll refer you to the solution I gave to the problem I linked above (it also includes a script I found handy to use).

    One thing I would add, is that to learn Photon, I followed this tutorial series. Whilst I didn't use his code, the chap explains the Photon architecture very clearly. There are other decent tutorials out there as well like this series.

    Hope this helps. :)
     
  5. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    Uhhh...it looks really complex to me at least. The only problem with this solution, is that I have to completely have to rebuild the whole game, and I want none of that considering how much I already anchieved with it. So, ill just try it out, and hopefully it will fix many problems.

    And it also looks like I have to figure out the username myself, because of lack of help with that. But yeah, hope Photon works. So...this is kinda not so good. :(
     
  6. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    Okay, I cheked it out, and, its...ehh. Its not helping with the username problems really, it only tells things about the lobby. I guess its something? Maybe?
     
  7. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    UNet is okay, if you use only the LLAPI part. If your intention to use HLAPI, I suggest looking into the HLAPI Pro (it's free, search the forum).

    Photon is great when you can afford their price tag for their cloud servers.

    Also, there's a dedicated subforum here, that is specific for multiplayer games, you'll probably receive a faster answer there.

    Also, you're not setting any data for the remote players. You need to set the SyncVar variable on the server (host), and other clients should receive it, and set text value to the value of SyncVar.
     
  8. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    Okay, I started working on Photon now, please dont make me get confused, because im already somewhat are! Just please dont throw 5 million possibilities at me! Thank you, I know you all want to help, I understand that! But now, im on Photon, I just want my game to work as it should! Thanks for the answers once again! :)

    EDIT: Just one question: What is LLAPI and HLAPI?
    EDIT 2: I have the free version of Photon, so I dont think I have to pay a penny for it.
     
    Last edited: Jul 6, 2018
  9. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    LLAPI is part of the UNet that does low-level operations, like sending / receiving packages. It operates on the transport level, and it's C++, which means no source code available. It's really good, and performs very well. Plus, it's supported.

    HLAPI is just custom (and poorly written in C# example) library on top of it.
    Every component made by UT for networking is HLAPI, but uses LLAPI beneath it.
    Due to some weird Unity policy they didn't assigned people to work on it for more than a year. Then stuff just went even weirder. You can probably find that drama thread on multiplayer sub-section of the forum.

    This is really dumbed down explanation. Here's link for more information:
    https://docs.unity3d.com/Manual/UNetUsingHLAPI.html
    Eventually you'll have to deploy your servers somewhere. Let's just say, it's not that easy to integrate their code elsewhere except their cloud service.
     
  10. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    Hmm pretty interesting! Thank you :p