RPC on local vs remote - issue with serialisation

I have a class which only contains float/enum/bool fields. If I run one one machine (as masterclient) the RPC call that sends an instance of the class works fine. If I run on two machines, the remote client fails to send the RPC to the masterclient - "Exception: cannot serialize()".

Note that the "HitPoint" field was a Vector3, which I thought Photon would serialize? I split this into floats while trying to track down this error - but I should be able to send Vector3/enum/etc - is that correct?

How can I figure out which field is causing the failure (if that's what it is)? Also, when running on one machine, does photon still perform serialisation? Can't understand why it doesn't fail in all cases either.

Thanks!

---

public enum EFFECT_TYPE
{
GENERAL,
DAMAGE_DIRECT,
OTHER
}

[Serializable]
public class Damage {

public EFFECT_TYPE EffectType { get; set; }

public float InitialDamage { get; set; }
public float DamagePerSecond { get; set; }
public float DamageDurationSeconds { get; set; }

public float HitPointX { get; set; }
public float HitPointY { get; set; }
public float HitPointZ { get; set; }

public bool HitOtherPlayer { get; set; }

public SpellDamage()
{
}

public Damage(float initialDamage, float damagePerSecond, float damageDurationSeconds)
{
//just assigns data to fields above - nothing special
}
}


photonView.RPC("ReceiveEffectServer", PhotonTargets.MasterClient, damage);

[PunRPC]
public void ReceiveEffectServer(Damage damage)
{
...
}

Comments

  • Keaneo
    Keaneo
    edited April 2018
    Oops - maybe I misunderstood? The parameters of the RPC call must be fundamental type - is that it? Not just a class that CONTAINS those types. If I register a "custom serialisation" (as in https://doc.photonengine.com/en-us/pun/current/reference/serialization-in-photon), can I pass the object as a parameter in the RPC call? i.e.

    photonView.RPC("ReceiveEffectServer", PhotonTargets.MasterClient, damage);
  • Hi @Keaneo,

    yes, you would have to register a Custom Type in order to serialize your object. Since you are just using types, that Photon can handle by default, you can think about sending all the data as an array of objects. So instead of sending the class object itself, you can use an object array containing all elements from that class object.

    Note that the "HitPoint" field was a Vector3, which I thought Photon would serialize?


    Vector3 is a registered type. PUN can handle these.