Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

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

  1. syedali

    syedali

    Joined:
    Jun 6, 2017
    Posts:
    2
    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:
    2,242
    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:
    2
    Thank You for your response!