RPC works for base classes?

friuns
friuns
i have class Player:Base

in Base i have SetID method (it marked with [RPC]

player.photoview.RPC("SetID") throws this error

PhotonView with ID 1000 has no method "SetID" marked with the [RPC](C#)

if not how i can implement it?

Comments

  • you need to put the RPC where its meant to be used, so either on the player or on a network management class (thats what you normally do cause nothing is worse than 'wild rpc everywhere' cause thats unmaintainable) that forwards the stuff through sendmessage / method calls to the right game object
  • thanks for reply, i just overrided method in derived class.
  • as long as you don't have 2 classes extending base that should work yeah :)

    but the question is: do you really want to waste so many network ivews. I personally don't want to, it only causes a lot of chaos and if you need a central AI / unit manager anyway and alike (and you will need it) then you are making your work just significantly more complicated than needed.

    I use a single global view for RPC, only OnPhotonSerializeView based objects get extra network views (this holds for Unity Networking, uLink as well as Photon Unity Networking)
  • sure i have 2 classes extending base why its not would work? its OOP, but I dont attach multiple scripts to gameObject
  • This has nothing to do with OOP at all, this is all about attributes and uniqueness.
    I could think of half a dozen reasons for why it technically should not work (and wouldn't work in unitys own networking) so its best you simply test.
    As PUN relies on unitys SendMessage it could potentially work but I never tested it as I don't create 'network spaghetti code' which is exactly what distributed RPCs generate.
  • i don't undestand what you talk about) you mean you create only one global networkView? for simple game it may work yes...

    unity network works well except it not support much players, i now porting project on PhotonNetwork.
  • it works for any kind of game.

    I create 1 global Network View for RPCs, thats the RPC communication channel. The RPCs are all within one network manager class which manages the whole data distribution, data caching etc in a single place. Depending on the task it will then forward received data to the corresponding manager class which will continue the work on it or as in our case I call uScript Events etc basing on it when I get corresponding PUN RPCs on the NetworkManager.

    The only case where more than a single network view is needed is when you use OnPhotonSerializeView cause that requires one view per serialized object. RPCs don't need that, RPCs only need to get passed along information of the target for which the information originally was and thats a thing you have to send along anyway, be it explicitely by passing it or by wasting resources through using multiple views which in the end does the same.
  • wasting resources? what you mean by that. its should be same where you send RPC in object itself or make networkManager.

    if you make NetworkManager and call all rpc here you need to specify extra class name and function name that is wasting resources, if its done already for you in network engine
  • Hi friuns,
    I found a solution.
    The unity photon plugin doesn't find the methods marked as RPC in a base class because it doesn't search for such methods up the in the class hierarchy. You can solve this problem doing the following:
    - Inside the Plugins folder of the Photon Unity Networking open the NetworkingPeer.cs file.
    - Search the line 1334. It looks like this.
    MethodInfo[] myMethods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
    
    - Delete the BindingFlags.DeclaredOnly. This flags specifies that only members declared at the level of the supplied type's hierarchy should be considered. Inherited members are not considered. Once deleted, it should look like this
    MethodInfo[] myMethods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
    

    So far everything is working alright for me, should I find a problem with this code change I'll post it here.
    Bye!