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?