Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • 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 Cryoblast · Aug 10, 2015 at 04:08 AM · networkinglobbyunity multiplayer

How to instanciate player prefab in a OnLobbyServerSceneLoadedForPlayer override ?

Hi everbody.

I'm in trouble with the UNET NetworkLobbyManager.

What I did :

In my lobby scene, the user can choose the character he want to play. So I have some variables in a custom lobbyPlayer for save this choice.

In the NetworkLobbyManager, the OnLobbyServerSceneLoadedForPlayer is overriden in order to instantiate the right prefab according to the data previously stored on the lobbyPlayer.

Here is my CustomNetworkLobbyManager class :

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 
 public class CustomNetworkLobbyManager : NetworkLobbyManager
 {
 
     public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
     {
         //Retrieve the lobby player connection object
         NetworkIdentity netId = lobbyPlayer.GetComponent<NetworkIdentity>();
         NetworkConnection conn = netId.connectionToClient;
 
         //Instantiate de right prefab from the spawn prefabs list according to the lobbyPlayer data
         CustomNetworkLobbyPlayer customLobbyPlayer = lobbyPlayer.GetComponent<CustomNetworkLobbyPlayer>();
         GameObject playerPrefab = spawnPrefabs[customLobbyPlayer.GetPlayerClass()];
         GameObject newGamePlayer = 
             (GameObject) GameObject.Instantiate(playerPrefab, Vector3.zero, Quaternion.identity);
 
         //Init player data from the lobbyPlayer data
         PlayerData playerData = newGamePlayer.GetComponent<PlayerData>();
         playerData.SetPlayerTeam(customLobbyPlayer.GetPlayerTeam());
         playerData.SetPlayerClass(customLobbyPlayer.GetPlayerClass());
 
         //Destroy old player object
         Destroy(gamePlayer.gameObject);
 
         //Switch control to new player object
         NetworkServer.ReplacePlayerForConnection(conn, newGamePlayer, 0);
 
         return true;
     }
 }

On the editor side the NetworkLobbyManager is setup like this : alt text

I have no dedicated server but a Host.

What I get

Whene I launch the game and select characters on both the client and the host, the game scene is loaded and the folowing Warning appears 4 times :

 Trying to send command for non-local player.
 UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)
 PlayerData:CallCmdTransmitPlayerTeam(Int32)
 PlayerData:SetPlayerTeam(Int32) (at Assets/Scripts/PlayerBehaviour/PlayerData.cs:38)
 CustomNetworkLobbyManager:OnLobbyServerSceneLoadedForPlayer(GameObject, GameObject) (at Assets/Scripts/Network/CustomNetworkLobbyManager.cs:22)
 UnityEngine.Networking.NetworkLobbyPlayer:OnLevelWasLoaded()

When I move the character on host-side, everything works fine.

But when I do so on client-side, the player position is not updated on host-side and the following Warning is thrown each time a sync packet is sent accross the network :

 Player unetview deleted when handling Command message [playerControllerId=0]
 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

More Precisions (maybe no correlation)

1) If I set the playerControllerId to 1 istead of 0 on the NetworkServer.ReplacePlayerForConnection() call (line 29 of the given script), I get the 4 usual "Trying to send command for non-local player" Warnings, but a 5th is thrown :

 ClientScene::InternalAddPlayer: playerControllerId higher than expected: 1
 UnityEngine.Networking.NetworkServer:ReplacePlayerForConnection(NetworkConnection, GameObject, Int16)
 CustomNetworkLobbyManager:OnLobbyServerSceneLoadedForPlayer(GameObject, GameObject) (at Assets/Scripts/Network/CustomNetworkLobbyManager.cs:29)
 UnityEngine.Networking.NetworkLobbyPlayer:OnLevelWasLoaded()

But this time, the player positions are proprely updated on both host and client.

2) If I launch the host via the .exe (not inside the uity editor), the game crash on selecting character with the following error :

 NetworkLobbyManager OnClientReadyToBegin no player at lobby slot 1
 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

In advance, thanks, and sorry for my english. I'll improve.

networklobbymanager.png (37.1 kB)
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 RemDust · Mar 13, 2017 at 06:42 PM 0
Share

Hi @Cryoblast did you manage to achieve what you were trying to do ?

avatar image Cryoblast · Mar 13, 2017 at 08:01 PM 0
Share

As far as I remember, the probleme disapeared when I upgraded to a later version of Unity.

avatar image RemDust · Mar 13, 2017 at 08:11 PM 0
Share

thanks man :)

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to filter Lobby filled matches(with max players) in UNET ListMatches()? 0 Answers

Change NetworkMatch's name, attributes, and password after creation 1 Answer

ListMatchResponse Matches Count is 0 on remote PC?!? Why is Matchmaking broken? 0 Answers

[Multiplayer Lobby] Spawned enemies not seen in client's space.... 1 Answer

Difference between lobby and network manager 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges