Confusion around Networking setup for non-game use

Hey there all

I’ve used NetworkServer and NetworkClient (Not NetworkManager) to create a network between a server (PC) and client (Android) device. For my app, there are no player / game items, just GUI. The network is established with no problems over my local network.

I am now trying to open a particular bit of GUI on the Client device by way of an RPC call (Imagine a big screen with a a secondary screen or tablet for entering details). I’ve made a prefab that contains the GUI (extends NetworkBehavior) and RPC calls. However it doesn’t appear to work, and if I add an instance of the GUI to the stage, it immediately gets disabled.

My project is attached. What am I missing in my understanding?

2646935–186477–UNetwork.zip (32.5 KB)

After the server starts you should spawn scene objects by NetworkServer.SpawnSceneObjects() or a method with a similar name (Too lazy to look at docs).
Also the client after connection should call ClientScene.Ready() to make itself ready. It works like this

When server and client connect, They can send messages to each other using NetworkClient.Send and NetworkServer.Send family of functions. But to have objects and use commands and RPCs the client should declare itself ready.
If the object is in the scene (networked object) then server should tells uNet that it should spawns objects.

The object get disabled if they have NetworkIdentity until server spawns them. Then they get spawned (get enabled) on server and all ready clients. Each new ready client will enable its objects as well.

Hope this helps

Hi Ashkan_gc, your help was invaluable in explaining this for me and I now have it working from Server to Client. The ready flag was the key here. Not sure how I missed that.

My only issue now is using RPC to talk back to the Server.

You send commands from client to server and ClientRPC from server to client but you should own the object to be able to send commands from it. SceneObjects are owned by server so no commands from them.
You have two options. Use messages from client to server so NetworkClient.Send with a custom Message type and a custom class with your data which is inherited from NetworkMessage.
Or
Spawn the object from server by using NetworkServer.AddPlayerForConnection instead of having it in the scene. You should do the spawn after you receive the message MsgType.AddPlayer from client and from client you can use ClientScene.AddPlayerXXX which I don’t exactly remember to request adding a player for the client. Also there is another way SpawnWithAuthority which I did not use but you should be able to say which connection is the owner of the object and can send commands for it.