Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

RPC issue

Discussion in 'Multiplayer' started by llavigne, Mar 4, 2008.

  1. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    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...

    Code (csharp):
    1.  
    2.  
    3. private var firing : boolean = false;
    4. //Enable or disable user controls
    5. function SetEnableUserInput(enableInput)
    6. {
    7.     queryUserInput=enableInput;
    8. }
    9.  
    10. function FixedUpdate()
    11. {
    12.     if(queryUserInput)
    13.     {
    14.         if (Input.GetButton ("Fire1")  !firing) NetworkView.RPC("Firing",RPCMode.All); // minimizing sendmessage traffic
    15.         else
    16.             if (firing) NetworkView.RPC("StopFiring",RPCMode.All);
    17.         if (Input.GetButtonDown("Eject")) NetworkView.RPC("Ejecting",RPCMode.All);
    18.     }
    19. }
    20.  
    21. @RPC
    22. function Firing()
    23. {
    24.     BroadcastMessage("Fire",SendMessageOptions.DontRequireReceiver);
    25.     firing = true;
    26. }
    27.  
    28. @RPC
    29. function StopFiring()
    30. {
    31.     BroadcastMessage("StopFire",SendMessageOptions.DontRequireReceiver); /// unity error here
    32.     firing = false; /// and here
    33. } /// and here
    34.  
    35. @RPC
    36. function Ejecting()
    37. {
    38.     BroadcastMessage("Eject",SendMessageOptions.DontRequireReceiver);
    39. }
    40.  
    41.  
    42.  
    43.  
    44.  
     
  2. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Code (csharp):
    1. NetworkView.RPC("Ejecting",RPCMode.All);
    should be...

    Code (csharp):
    1. networkView.RPC("Ejecting",RPCMode.All);
    No capital N on networkView
     
  3. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    thanks -

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

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,304
    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" ;-)

    Sunny regards,
    Jashan
     
  5. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    Clear - This required a notion of what a classes and a static are ;-)

    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 ...
     
  6. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    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