• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by LutzKellen · Nov 29, 2016 at 08:15 AM · networkingmultiplayernot workingmultiplayer-networkinglobby

[UNET] LobbyManager - OnLobbyServerSceneLoadedForPlayer() not executing for clients

I am using the LobbyManager asset as found on the Unity Store. Specifically, I am using the one integrated with the Meteroid (Asteroids) game. I have edited only one thing so far from the original scripts.

I have edited the NetworkLobbyHook.cs script to allow me to change player's colors, and their goal's colors. Along with this it changes their object's names. Here is my changes:

 using UnityEngine;
 using Prototype.NetworkLobby;
 using System.Collections;
 using UnityEngine.Networking;
 
 [NetworkSettings (channel=0, sendInterval=0.1f)]
 public class NetworkLobbyHook : LobbyHook 
 {
     public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer, GameObject gamePlayer)
     {
         LobbyPlayer lobby = lobbyPlayer.GetComponent<LobbyPlayer>();
         CTFColorChangerScript player = gamePlayer.GetComponent<CTFColorChangerScript>();
         CTFGoalColorChangerScript goal = GameObject.FindGameObjectWithTag ("Goal" + (lobby.slot + 1)).GetComponent<CTFGoalColorChangerScript>();
         if( goal != null ) {
             goal.gameObject.GetComponent<Renderer>().material.color = lobby.playerColor;
             goal.goalColor = lobby.playerColor;
             goal.ownerName = lobby.playerName;
             player.name = lobby.playerName;
             player.playerName = lobby.playerName;
             player.color = lobby.playerColor;
         }
     }
 }

For my channels I have tried using Reliable State Update, Reliable Sequenced, and Unreliable. Channel #0 is currently Reliable Sequenced. Channel #1 is Unreliable.

The issue is, when the player connects, we have no issues changing colors or names. However when both players ready up, and the game advances to the game scene, there is a chance that the client will become the host as well. The client's object is still spawned in the scene, but his color, name, and controls are all disregarded. Using Debugs, it is very clear that when the OnLobbServerSceneLoadedForPlayer() is broken, it is not being called on the client whatsoever. The debugs both show up on the Host, and the host gets the error:

 Assets/WRAPPER/SampleScenes/Scripts/NetworkLobbyHook.cs:16)
 Prototype.NetworkLobby.LobbyManager.OnLobbyServerSceneLoadedForPlayer (UnityEngine.GameObject lobbyPlayer, UnityEngine.GameObject gamePlayer) (at Assets/WRAPPER/Lobby/Scripts/Lobby/LobbyManager.cs:333)
 UnityEngine.Networking.NetworkLobbyManager.SceneLoadedForPlayer (UnityEngine.Networking.NetworkConnection conn, UnityEngine.GameObject lobbyPlayerGameObject) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkLobbyManager.cs:147)
 UnityEngine.Networking.NetworkLobbyManager.OnServerSceneLoadedMessage (UnityEngine.Networking.NetworkMessage netMsg) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkLobbyManager.cs:463)
 UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:453)
 UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:409)
 UnityEngine.Networking.NetworkConnection.TransportRecieve (System.Byte[] bytes, Int32 numBytes, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:561)
 UnityEngine.Networking.NetworkServer.OnData (UnityEngine.Networking.NetworkConnection conn, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:753)
 UnityEngine.Networking.NetworkServer+ServerSimpleWrapper.OnData (UnityEngine.Networking.NetworkConnection conn, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:1845)
 UnityEngine.Networking.NetworkServerSimple.HandleData (Int32 connectionId, Int32 channelId, Int32 receivedSize, Byte error) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServerSimple.cs:382)
 UnityEngine.Networking.NetworkServerSimple.Update () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServerSimple.cs:248)
 UnityEngine.Networking.NetworkServer.InternalUpdate () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:705)
 UnityEngine.Networking.NetworkServer.Update () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:655)
 UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:1060)

As it seems, it can't find the goal. Probably because it's trying to find a goal when it already did that for the host. I'm really not sure at this point. The client also doesn't spawn a player object at all, other than the host's. The host's scene has a player prefab (default settings of that prefab), spawned where he should be, and the object's name has been changed to "".

Any ideas?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by LutzKellen · Dec 05, 2016 at 07:33 AM

This issue has been solved, the problem was, I was attempting to access a script on another object with a Network Identity. This object was not guaranteed to be loaded in before the player script runs. If it wasn't, it broke.

Why it worked some of the time, I have no idea. A suggestion is that the documentation should state that you should not attempt to access objects with Network Identities in this function, as they are not guaranteed to be initialized. However, I'm sure that's just common knowledge I forgot somewhere along the way.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

OnStart ___ vs OnLobbyStart ___ methods from NetworkManager and NetworkLobbyManager 1 Answer

Unity networking tutorial? 6 Answers

NetworkLobbyPlayer SendNotReadyToBeginMessage doesn't exist? 1 Answer

[Unet] NetworkManager singleton auto-destruction 0 Answers

UNET Multiplayer Lobby not creating an instance of the lobby player 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges