- Home /
Unet - PlayerPrefab changed on host side, but not updated on client side ?
NetworkLobbyManager spawns a temporary player into the play scene, which I want to replace with user chosen player prefab.
temporary player has a following script
public class ReplacePlayer_Net : NetworkBehaviour
{
public int chosenCharacter;
public GameObject[] characters;
public void ReplacePlayerButton()
{
chosenCharacter = //whatever character user choses
CmdReplacePlayer(characters[chosenCharacter]);
// is called after 1 sec because calling it on start gives "This Mesh Collider requires the mesh to be marked as readable in order to be usable with the given transform." error
}
[Command]
public void CmdReplacePlayer(GameObject newPrefab)
{
NetworkConnection conn = this.connectionToClient;
GameObject NewPlayer = Instantiate(newPrefab, transform.position, transform.rotation);
NetworkServer.Spawn(NewPlayer);
NetworkServer.Destroy(gameObject);
NetworkServer.ReplacePlayerForConnection(conn, NewPlayer, 0);
if (Debug.isDebugBuild)
{
Debug.Log("Player Replaced");
}
}
it does destroy old prefabs on both client and host side but new prefabs are only visible on host side, client side stays empty.
how do I call the change on client side ?
Answer by $$anonymous$$ · Aug 09, 2019 at 05:08 PM
I'm retarded. I spent 2 days on this. turns out I forgot to add prefabs to registered spawnable prefabs.
Your answer
Follow this Question
Related Questions
Unity Multiplayer - Instantiate prefab 1 Answer
[Networking] Player prefab in a Hearthstone-like card game 0 Answers
Creating a client player and a host player in a single device and networking them correspondingly 0 Answers
I have problem with synchronize multiplayer player position... 0 Answers
Unity Client & Server Socket 1 Answer