Why does localscale of transform set randomly to (0,1,1) and (0,0,0) on level load?

Basically, I’m building a multi-player RPG and everything seems to go fine with the networking. Except that RANDOMLY a Prefab will be set to a scale of either (0,1,1) or (0,0,0). It is never the local player’s prefab, and it happens more on the host than the clients. Just did some debugs on local and world scale: both claim it’s set to 1.0, 1.0, 1.0 even when I see it as 0, 0, 0 in the inspector - and hardcoding after instantiation and level-load don’t seem to matter…(2nd script happens after level load setting spawn point)

Really, none of that should matter since I use the same RPC to instantiate for host and client.

void Client_LoadMultiplayerScene(string scene, int prefix)
{

// Create Player Prefab
GameReference.localPlayerObject = Network.Instantiate(playerCharacterPrefab, Vector3.zero, Quaternion.identity, 0) as GameObject;
GameReference.localPlayerObject.name = GameReference.playerCharacterScript.Name;
GameReference.localPlayerObject.transform.localSca le.Set(1,1,1);


// So we only recieve messages for new prefix
Network.SetLevelPrefix(prefix);


Application.LoadLevel(scene);

}

So this function instantiates the player prefabs and adds them to the list of players. The Prefabs have DoNotDestroyOnLoad called to preserve their stats and data. I’ve been having this problem for a while so I decided to try and hard code to localScale here, where I move everyone to the spawn point:

// Move Players to Level Spawnpoint
for(int cnt = 0; cnt < GameReference.multiplayerManagerScript.NetworkedPl ayerPrefabs.Count; cnt++)
{
GameReference.multiplayerManagerScript.NetworkedPl ayerPrefabs[cnt].transform.localScale.Set(1,1,1);
GameReference.multiplayerManagerScript.NetworkedPl ayerPrefabs[cnt].transform.position = spawnPoint.transform.position; 
}

The players all get moved to the spawn point, but their localScale still seems totally random. Maybe I just hard coded it wrong, but honestly I don’t see why I should have to hard code it at all. Perhaps it’s some flaw with Network.Instantiate? I am also using the PlayerRemote and PlayerLocal scripts for interpolation from the unity wiki (perhaps something wrong in there?)

This problem has haunting me for a while now. I workaround it by always hosting with editor execution and simply setting the scale to 1,1,1 in the inspector, but obviously I can’t keep doing that. :stuck_out_tongue:

Thanks to anyone who takes the time. Cheers.

  • Erik

I met some similar issue too. It seems like the localScale.Set() function takes the parents’ scale into consideration as well.
You might try:

 transform.localScale = new Vector3(0.0f, 0.0f, 0.0f);

at least this works for me.