Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different scenes for server and clients using Unity networking HLAPI

Tags:

unity3d

I created a networtk app with some clients connected to a pure server (not host) using Unity networking high level API (HLAPI).

Here is what I intend to achieve:

My server has the scenes ServerOffline (simply displays OFFLINE with canvas + text) and ServerOnline (display infos about connected clients also with canvas + texts) configured into a NetworkManager offlineScene and onlineScene properties. That NetworkManager is obviously started as server for build 1.

Now, any client has also two scenes but not the same ones as the server. ClientOffline displays DISCONNECTED with canvas + text and ClientOnline shows the app itself (cube shooting spheres). The same NetworkManager is used but offlineScene and onlineScenes properties are set with client scenes (not server scenes) before starting it as client for Build 2.

Here is what I get:

When the client connects to the server, the server forces ITS scenes to the clients. The scenes I expected on clients are not loaded.

QUESTION:

How can I operate my server + clients using different scenes on both ends using Unity networking HLAPI? Is the NetworkManager approach just wrong? It would be sad to not use it since NetworkManager does so much good stuff already.

Thank you very much!

like image 513
RCYR Avatar asked Dec 01 '16 20:12

RCYR


People also ask

Is Unity a client server?

The local client uses the same Unity scenes and objects as the server, and communicates internally using message queues instead of sending messages across the network. But, to HLAPI code and systems, the local client is just another client, so almost all user code is the same whether a client is local or remote.

Does Unity have built in Networking?

Engine and Editor integrationUnity's networking is integrated into the engine and the editor, allowing you to work with components and visual aids to build your multiplayer game. It provides: A NetworkIdentity component for networked objects.

What is client Unity?

The Unity Client is an OnBase desktop application, offering the familiar look-and-feel of Microsoft Office products. With intuitive ribbon-style toolbars and tabs and easy access to features, users can easily navigate and perform their primary job tasks with little-to-no training.


Video Answer


1 Answers

I will answer my own question since I have found the answer. I have a base scene named "Base.unity" which contains the NetworkManager.

I have created two more scenes named "Offline.unity" and "Online.unity" set to that NetworkManager properties "offlineScene" and "onlineScene" respectively. The "Offline.unity" scene has only a canvas showing full screen "OFFLINE" in colored text. The "Offline.unity" scene is used by both the client and the server as it is.

However, I recall my goal, I want to have different scenes on both ends whenever online. I created the scene "DektopClientOnline.unity" which contain only the specialized assets for the desktop client (no camera, no light, etc. since all that common stuff is in the "Online.unity" scene) and I have created the scene "ServerOnline.unity" for server specialized assets (basically a canvas showing connected clients, etc. again with no camera, light, etc.).

I have specialized the NetworkManager (called AppNetworkManager) and essentially overriden two functions:

public override void OnClientSceneChanged(NetworkConnection conn)
{
    SceneManager.LoadScene("DesktopClientOnline", LoadSceneMode.Additive);
    ClientScene.Ready(conn);
    ClientScene.AddPlayer(conn, 0);
}

public override void OnServerSceneChanged(string sceneName)
{
    SceneManager.LoadScene("ServerOnline", LoadSceneMode.Additive);
}

Here is what happens :

Whenever the server goes online, the OnServerSceneChanged callback is invoked when the "Online.unity" scene (configured into the NetworkManager) is loaded. Thereby, I simply "inject" the specialized contents of "ServerOnline.unity" into "Online.unity". I have what I wanted on the server.

Then a client connects to the server. The OnClientSceneChanged callback is invoked when then "Online.unity" scene is loaded yet again but this time on the client. I "inject" the specialized contents of "DesktopClientOnline.unity" into "Online.unity". I have what I wanted on the client.

Hope this can help for anyone!

like image 118
RCYR Avatar answered Oct 23 '22 03:10

RCYR