RPC issue (380573)

Unity is returning 3 " BCE0020: An instance of type ‘UnityEngine.NetworkView’ is required to access non static member ‘RPC’." in the position indicated in the script.

The script is attached to a NetworkView component and state sync is turned off…

private var firing : boolean = false;
//Enable or disable user controls
function SetEnableUserInput(enableInput)
{
	queryUserInput=enableInput;
}

function FixedUpdate()
{
	if(queryUserInput)
	{
		if (Input.GetButton ("Fire1")  !firing) NetworkView.RPC("Firing",RPCMode.All); // minimizing sendmessage traffic
		else
			if (firing) NetworkView.RPC("StopFiring",RPCMode.All);
		if (Input.GetButtonDown("Eject")) NetworkView.RPC("Ejecting",RPCMode.All);
	}
}

@RPC
function Firing()
{
	BroadcastMessage("Fire",SendMessageOptions.DontRequireReceiver);
	firing = true;
}

@RPC
function StopFiring()
{
	BroadcastMessage("StopFire",SendMessageOptions.DontRequireReceiver); /// unity error here
	firing = false; /// and here
} /// and here

@RPC
function Ejecting()
{
	BroadcastMessage("Eject",SendMessageOptions.DontRequireReceiver);
}
NetworkView.RPC("Ejecting",RPCMode.All);

should be…

networkView.RPC("Ejecting",RPCMode.All);

No capital N on networkView

thanks -

I’d like to decipher the error messages more often, what’s the trick ? Is there a translation table to human language, somewhere ?

Well, in this case, what it means is this:

There’s NetworkView, which is a class. And there’s networkView which is a member instance variable inherited from Component (both GameObject and MonoBehavior are subclasses of Component). RPC(…) is an instance method which means that it operates on an instance (which is the usual case in object oriented programming). In the Unity API, there’s also a lot of static methods, which operate on the class.

So the error message you received basically means “hey homes, there is a method called RPC in the class NetworkView, but it’s not declared static so you better send it to an instance of NetworkView instead of the class itself” :wink:

Sunny regards,
Jashan

Clear - This required a notion of what a classes and a static are :wink:

The odd thing was the error didn’t log at the NetworkView.RPC or at the first @RPC but in the second @RPC - it’s trying to confuse me even more …

Never rely on the line numbers a compiler gives you in an error message.

Just always use those line number as a suggestion as to where you should start looking.

-Jeremy