• 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 /
  • Help Room /
avatar image
0
Question by camfred · Jan 31, 2017 at 12:57 AM · networkingnetworkplayer

Trouble Getting NetworkLobby to update player names on Client

I'm using the NetworkLobby from the asset store. I'm attempting to take the form input (player name) and update the gameplayer using the associated lobbyplayer object. Per various tutorials and samples, the magic place for that to happen is apparently in the OnLobbyServerSceneLoadedForPlayer() method. I have the following code running on the Lobby Manager.

     public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer, GameObject gamePlayer) {
         LobbyPlayer lPlayer = lobbyPlayer.GetComponent<LobbyPlayer>();
         Player gPlayer = gamePlayer.GetComponent<Player>();
         gPlayer.playerName = lPlayer.playerName;
         }
     }

So far so good. The Player object has a synvar with a hook...

     [SyncVar(hook = "OnNameChanged")] public string playerName;

And the hook looks like this:

     void OnNameChanged(string value) {
         
         playerName = value;
         gameObject.name = "Player (" + playerName + ")";
         if (GetComponentInChildren<Text>(true) != null) {
             GetComponentInChildren<Text>(true).text = playerName;
         }
     }

When I run this, from the server's perspective, everything goes as it should. All the players get named correctly and their Text object gets set. From the client's perspective, player name never gets set for any player. What am I missing?

Any help would be very much appreciated, I've been struggling with this for a while.

Comment
Add comment · Show 3
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
avatar image Mike-Geig ♦♦ · Jan 31, 2017 at 04:04 PM 0
Share

Can you run the build as the server and then run the editor as a client and use the inspector to determine if the value is being set at all? Perhaps it just cannot find the text component to visually update it but the variable is still receiving its value. Otherwise, you may need to use break points to follow the full flow of logic from the lobby hook to the name change hook

avatar image camfred Mike-Geig ♦♦ · Feb 02, 2017 at 04:00 PM 0
Share

Value not getting set at all by client. The more i test this, the more erratic it appears to be. I believe it has something to do with my player object prefab taking a bit to load (using uma). What's odd about it is the player lobby seems willing to move on to the scene with the client player object not fully loaded.

avatar image Mike-Geig ♦♦ camfred · Feb 02, 2017 at 04:03 PM 0
Share

What's uma? Also, delayed loading shouldn't matter. SyncVars are updated as soon as the object manages to load in. Can you submit a stripped down version of your project (just the bits that you can share / show the error) as a bug and send me the case number?

0 Replies

· Add your reply
  • Sort: 

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

116 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

i just can't seem to figure out how to make a voting system, using SyncVar hooks and commands 0 Answers

How to disbale a network start position on runtime 0 Answers

Network server spawns both players as client or server,Players in network game both spawn as client or server 1 Answer

NetworkServer is not active. Cannot spawn objects without an active server. 0 Answers

i want to create a custom network lobby manager. How can i script it? 0 Answers

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