Search Unity

Message Passing b/w “LAN Server Only” and “LAN Client” on Different Scenes in Unity

Discussion in 'Multiplayer' started by syedali, May 15, 2018.

  1. syedali

    syedali

    Joined:
    Jun 6, 2017
    Posts:
    8
    Hi, I want to pass message back and forth on client and server which are on different scenes, how can I do that in Unity?**

    Following is my Scenario:-
    I have 5 scenes-

    1. BaseScene (2) OfflineScene (3) OnlineScene (4) ClientOnline (5)
    ServerOnline.

    All these scenes have button having text of the names of the scenes.
    On Base Scene, I have add empty game object on which i have placed "customNetworkScript" which extends from "NetworkManager" script and also placed "Network Manager HUD" on it. Following is the code which i have placed in "customNetworkScript":-


    Code (CSharp):
    1. public class customNetworkScript : NetworkManager {
    2.              
    3.             public override void OnClientSceneChanged(NetworkConnection conn)
    4.                 {
    5.                     SceneManager.LoadScene("ClientOnline", LoadSceneMode.Single);
    6.                     ClientScene.Ready(conn);
    7.                     ClientScene.AddPlayer(conn, 0);
    8.                 }
    9.          
    10.                 public override void OnServerSceneChanged(string sceneName)
    11.                 {
    12.                     SceneManager.LoadScene("ServerOnline", LoadSceneMode.Single);
    13.                 }
    14.         }
    I have placed "OfflineScene" and "OnlineScene" in the fields, named "Offline Scene" and "Online Scene" in "Network Manager" component. Also have placed an empty prefab in "Spawn Info" in "customNetworkScript" and it has component "Network Identity" on it. Now when i run project, on one instance, I click on "LAN Server only" and on another instance, I click on "LAN Client". And I get my respective scenes on both the instances -> "ServerOnline" appear on instance where I click "LAN Server only" and "ClientOnline" appear on other instance.
    What I want is, when i click on "ServerOnline" button, a message string will pass on to "ClientOnline" scene and same happens in backward direction when i click on "ClientOnline" button.

    I have tried "Rpc" and "Command" but they only work when I click on "LAN Host" instead of "LAN Server Only".
    I have tried very hard but couldn't find anything useful. It will be a great pleasure if someone explain to me in detail along with the code, how can I achieve this.

    ThankYou Very Much for Your Time.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The Unet HLAPI is designed around the idea that the server and all clients are running the same scene, not different scenes, so this won't be the only trouble you run into. But, to answer your question, use Unet Messages.

    https://docs.unity3d.com/Manual/UNetMessages.html
     
    syedali likes this.
  3. syedali

    syedali

    Joined:
    Jun 6, 2017
    Posts:
    8
    Thank You for your response!
     
  4. syedali

    syedali

    Joined:
    Jun 6, 2017
    Posts:
    8
    After hours of research and hard work, finally find the exact solution for my problem. I will refer to this asset if someone still stuck on it:

    This asset is well documented and will tell you all about how you can do dedicated/pure server and client networking:-

    Asset Link: UNET Basic(Dedicated)Server_Client setup - Asset Store[^]

    If someone still don't understand it feel free to ask me. I will try my best.