- Home /
Problem is not reproducible or outdated
Huge FPS Drop after switching player objects in multiplayer.
I have a bunch of playable ships in a multiplayer scenario.
If I change the player prefab to use to either ship - it spawns in fine at the start with 70+ fps.
However if I call this command:
[Command]
public void CmdChangeShip(NetworkInstanceId NID, int SelectedShipPrefabIndex)
{
Transform shipTransform = gameObject.transform;
GameObject PlayerShip = NetworkServer.FindLocalObject(NID);
NetworkConnection NetCon = PlayerShip.GetComponent<NetworkIdentity>().connectionToClient;
Transform WhereToSpawn = PlayerShip.transform;
GameObject NewShip = Instantiate(ShipPrefab[SelectedShipPrefabIndex], WhereToSpawn.position, WhereToSpawn.rotation);
NetworkServer.Spawn(NewShip);
if(NetworkServer.ReplacePlayerForConnection(NetCon, NewShip, 0))
{
NetworkServer.Destroy(PlayerShip);
}
base.OnStartLocalPlayer();
}
The code works fine - in that the player is replaced with the 'new ship'.. but I get a massive drop in FPS. from 70 to 24ish.
If I then try to 'switch back' by calling this method again, with another ship selected, unity editor just crashes.
I'm wondering what could cause this kind of behaviour? Is there more that I need to do in this method to remove the old ship completely? Like I said, if i spawn directly as one of these ships, everything works fine - but after changing using this command, everything goes pear shaped.
Thanks in advance for any help you can provide.
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
The magic key to networking? 0 Answers
[HELP]Photon multiple Prefabs/Characters 0 Answers
OnDeserialize is not being called on by client. 0 Answers
[uLink] Instantiation 0 Answers