This baffled me for long enough. I have this small script here that crashes unity every time a RPC is called from it. It doesn’t matter what the RPC does, even if it’s empty. Unity just dies.
I’ve submitted a bug report, but the Unity team haven’t answered yet.
This is the script (C#):
using UnityEngine;
public class SpawnScript : MonoBehaviour
{
public Transform PlayerPrefab;
private Transform spawned;
public Color PlayerColor = Color.white;
void OnLevelWasLoaded ()
{
if (Application.loadedLevel != 0 && Application.loadedLevel != 1)
Spawnplayer();
}
void Spawnplayer ()
{
spawned = Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 0) as Transform;
networkView.RPC("SetPlayerDetails", RPCMode.AllBuffered, GetComponent<LocalClient>().PlayerName);
}
[RPC]
void SetPlayerDetails(string pName)
{
spawned.name = pName;
spawned.renderer.material.color = PlayerColor;
}
void OnDisconnectedFromServer(NetworkDisconnection info)
{
Application.LoadLevel(0);
GetComponent<Menus>().CurrentWindow = 0;
}
}
Any ideas?
Interesting observation: Delaying the RPC call for a second (using
– asafsitneryield return new WaitForSeconds(1)) does not cause Unity to crash. Why?Update! This behaviour seems to repeat itself when the RPC is sent 'between' loading levels. If someone can confirm this it will be tremendously helpful.
– asafsitnerAnother update: Apparently Unity crashes whenever an exception is thrown during level loading. It happened to me today when trying to display an unassigned texture during level load with
– asafsitnerLoadLevelAsync. I'd be glad if someone can confirm this as well.