RPC argument using derived class

I have a parent class Fruit:
public class Fruit {}

and a derived class Apple:
public class Apple : Fruit {}

I have an RPC defined this way:
[RPC]
public void Slice (Fruit f) {
\\ slice fruit.
}

When I call the RPC:
Fruit fruit;
mPV.RPC("Slice", PhotonTargets.All, fruit); \\ This is fine.

Apple apple;
mPV.RPC("Slice", PhotonTargets.All, apple); \\ Error: no method "Slice" that takes 1 argument : Apple

It works if I define an additional method like this:
[RPC]
public void Slice (Apple a) {
Slice ((Fruit) a);
}

But that is a rather ugly solution. I'm very much appreciate your help on this! :geek:

Comments

  • Currently, the check of RPC-method parameters is strict, ignoring the class hierarchy. That's why this doesn't work in the first place.
    I can't do this for you now but check the Photon Unity Networking code yourself where we "execute" the RPCs. This code could surely be modified to respect inheritance.

    As general comment: In networking, more classes are not always better. While object orientation is not bad or anything, it takes some extra bandwidth to send custom classes. The more you send the worse.
  • Thanks for the explanation!