Unity crashes when doing an RPC.

Hey all, I’m trying to do a RPC but both the Unity Designer and Unity WebPlayer crash whenever it tries to do it. I therefore have no way of knowing what im doing wrong.

The GameObject that is running the below code is created byNetwork.Instantiate from a prefab with a NetworkView already attached.

Here is my update code:

void FixedUpdate()
    //Unrelated code generating vehicles wheel movement.
    if(networkView.isMine)
    {
	    SetInputHorizontal(Input.GetAxisRaw("Horizontal"));
	    SetInputHorizontal(Input.GetAxisRaw("Vertical"));
    }
    //Unrelated code setting wheel movement.
}

Here are the RPC functions:

	[RPC]
	public void SetInputVertical(float InputVal)
	{
		if(networkView.isMine && vertInput != InputVal)
		{
			networkView.RPC("SetInputVertical", RPCMode.All, InputVal);
		}
		vertInput = InputVal;
	}
	
	[RPC]
	public void SetInputHorizontal(float InputVal)
	{
		if(networkView.isMine && horizInput != InputVal)
		{
			networkView.RPC("SetInputHorizontal", RPCMode.All, InputVal);
		}
		horizInput = InputVal;
	}

The game will run, but whenever I press an input key triggering the change in input, thus triggering the RPC, Unity totally crashes.

Anyone got an idea as to what I’m doing wrong?

Take a look at this function-

[RPC]
public void SetInputVertical(float InputVal)
{
   if(networkView.isMine && vertInput != InputVal)
   {
     networkView.RPC("SetInputVertical", RPCMode.All, InputVal);
   }
   vertInput = InputVal;
}

What does it do?

First, it checks to see if the networkView is local. If it is, it sends an RPC to everyone, and finishes.

However, ‘everyone’ includes the local machine! So every time this RPC gets called, it recursively calls itself again! So, every time you call this function (RPC or not), it will create an infinite loop.

You should use RPCMode.Others, instead.