Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Third Party LAN Host UI Conversion

Discussion in 'Multiplayer' started by Simplisticated_Development, Aug 20, 2023.

  1. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61
    Hello all-

    I am new to Unity multiplayer. When I add the Network Manager HUD and I get the UI on the screen. The UI, though, is ugly and not able to be used for a game release. I looked through documentation, and I understand that Network Manager HUD isn't meant to be professional looking. What I don't understand, however, is how you can make the Network Manager HUD into your own UI. The online documentation is old and deprecated and unclear, so I was wondering if anyone could give me a push in the right direction.

    Thanks in advance-
    -Simplisticated_Developments
     
  2. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61
    Screenshot 2023-08-20 at 9.51.45 AM.png
    Here's an error I get if I try to input my own script.
     
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    598
    You're not using UNet are you as that is deprecated.

    For Netcode for GameObjects add a button to your own scene UI with it's OnClick event calling a routine containing this:
    Code (CSharp):
    1. NetworkManager.Singleton.StartHost();
     
  4. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61
    I'm using mirror, which is the same thing.

    Could you just supply me with an example of an entire script? I think I am misunderstanding the concept of having the OnClick event call a routine.

    Here is what I tried: Screenshot 2023-08-20 at 6.39.15 PM.png which I am pretty sure is the entirely wrong move. I am new to C# in general so I'm really sorry about this...

    Thanks in Advance!! :)
    Simplisticated_Developments
     
  5. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    598
    It's a long time since I used Mirror and it differs to NGO in that you derive your own network manager from the one provided. StartHost doesn't return a value so you need to override OnStartHost to know when its started.

    Code (CSharp):
    1. public class MyNetworkManager : NetworkManager
    2. {
    3.     public void OnClickStartHost()
    4.     {
    5.         StartHost();
    6.     }
    7.  
    8.     public override void OnStartHost()
    9.     {
    10.         base.OnStartHost();
    11.  
    12.         Debug.Log("MyNetworkManager Host started");
    13.     }
    14. }
    Add OnClickStartHost() as your button's OnClick event and you should be good to go.
     
  6. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61
    So what would be the commands/scripts for all of the other LAN buttons like starting as a client?
     
  7. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61
    Okay...something's wrong...

    So I have the script input here (Script name is HUDfunc) Screenshot 2023-08-21 at 9.23.08 PM.png with your code example. When I add this script to a button and try to find the OnClick event, I am presented with no choices:
    Screenshot 2023-08-21 at 9.22.03 PM.png If I hover over mono script I am asked to input the string name, which I'm pretty sure that I don't have.

    Any ideas?
     
  8. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    598
    You'll have to do a bit of digging, first port of call would be the API documentation.

    The file name and class name need to match, also you can't add the script directly to the OnClick event, it has part of a GameObject.

    If you're just starting out with Unity and C# get a good grounding in those first before attempting anything multiplayer, it will be a real struggle to try learn everything all at once.
     
  9. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61
    And when I put the script with your code in, I

    Thanks for the tip. I've had a lot of spare time so I'm able to learn both C#/Unity and Network within reason.

    One final question (I think)...How do I make the button disappear once it has been clicked and I am in the online scene? How do I make it reappear when I exit?
     
  10. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    598
    Going by the API you'll want to take a look at the NetworkManager's offlineScene and onlineScene.
     
  11. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61
    Okay, I'll take a look...that's what I thought of before...
     
  12. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61
    Okay...I have been toying around some more and I am ALMOST at the solution. I have tried to use the same script example that you gave me, and then switch everything to client. (i.e OnClickStartHost is now OnClickStartClient), but I still cannot find a way to make the game join as a client...and I also need to figure out how to successfully leave a server when it's joined.

    I think one of my issues is that the network manager comes with the "HUDfunc" script. I need to be able to have the HUDfunc be just the commands for starting servers/joining as a client/etc. , but I am still struggling to figure out how to solve this issue...

    Thanks for a reply in advance :D

    (By the way, I am not just continuing this post for just my own reasons, but I'm hoping that you can help everyone out with such an under-documented UI issue.)
     
  13. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61
    Screenshot 2023-08-23 at 7.41.21 PM.png Above is the script I was going to use. (Green text is my addition to the script)...right now if I actually use this method and plug in the commands to another button, it just starts a host.
     
  14. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    598
    You can have the host and client sharing the same button if you use ParrelSync (which is pretty much a necessity in case you're not already using it), and you can move out the connection calls into your own class by adding a reference to the network manager in the editor:

    Code (CSharp):
    1. public class SampleSceneController : MonoBehaviour
    2. {
    3.     [SerializeField] MyNetworkManager myNetworkManager;
    4.  
    5.     public void OnClickNetworkStart()
    6.     {
    7.         if (!ParrelSync.ClonesManager.IsClone())
    8.         {
    9.             myNetworkManager.StartHost();
    10.         }
    11.         else
    12.         {
    13.             myNetworkManager.StartClient();
    14.         }
    15.     }
    For disconnecting have an onlineScene following the same principle above.

    ChatGPT will be able to answer a lot of your questions if you've not tried it already.
     
  15. Simplisticated_Development

    Simplisticated_Development

    Joined:
    Jun 26, 2023
    Posts:
    61

    Okay, so now the multiplayer seems to work okay.

    But for some reason when I spawn into the multiplayer match, I cannot move the character prefab. It has all of the parts plugged in (including net identity and transform), and it moves in other scenes, just not the online one.
     
  16. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    598
    I can't be much help I'm afraid, I've not looked at any player control in Mirror or NGO. It's recommended if you need help with Mirror to ask on their Discord channel.