Class of variables into Hashtable

Options
Hello!
Just wanted to ask if its possible to assign class of variables into customPropeties like this:

[code2=csharp]public class someVars {
public string var1;
public float var2;
}

public someVars manyVars;

Hashtable setVarsToProperties = new Hashtable() {{"Setting", manyVars}};
PhotonNetwork.room.SetCustomProperties(setVarsToProperties);[/code2]

When I try to use this method it gives me an error:
SystemException: cannot serialize(): VehicleSync+ownerProperties
ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.SerializeHashTable (System.IO.MemoryStream dout, System.Collections.Hashtable serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.SerializeParameterTable (System.IO.MemoryStream memStream, System.Collections.Generic.Dictionary`2 parameters)
ExitGames.Client.Photon.Protocol.SerializeOperationRequest (System.IO.MemoryStream memStream, Byte operationCode, System.Collections.Generic.Dictionary`2 parameters, Boolean setType)
ExitGames.Client.Photon.EnetPeer.SerializeOperationToMessage (Byte opc, System.Collections.Generic.Dictionary`2 parameters, EgMessageType messageType, Boolean encrypt)
ExitGames.Client.Photon.EnetPeer.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypt, EgMessageType messageType)
ExitGames.Client.Photon.PeerBase.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypted)
ExitGames.Client.Photon.PhotonPeer.OpCustom (Byte customOpCode, System.Collections.Generic.Dictionary`2 customOpParameters, Boolean sendReliable, Byte channelId)
LoadbalancingPeer.OpSetPropertiesOfRoom (System.Collections.Hashtable gameProperties, Boolean broadcast, Byte channelId) (at Assets/_CustomAssets/Photon Unity Networking/Plugins/PhotonNetwork/LoadbalancingPeer.cs:197)
LoadbalancingPeer.OpSetCustomPropertiesOfRoom (System.Collections.Hashtable gameProperties, Boolean broadcast, Byte channelId) (at Assets/_CustomAssets/Photon Unity Networking/Plugins/PhotonNetwork/LoadbalancingPeer.cs:180)
Room.SetCustomProperties (System.Collections.Hashtable propertiesToSet) (at Assets/_CustomAssets/Photon Unity Networking/Plugins/PhotonNetwork/Room.cs:212)
VehicleSync.Update () (at Assets/_CustomAssets/Scripts/Vehicle/VehicleSync.cs:47)

Comments

  • Tobias
    Options
    Photon does not know how to serialize your class "someVars" in that case.

    You could solve this in two ways:
    • Implement and register custom type serialization methods.
      In this case, you would implement two methods: one that writes this class into a byte[] and one that creates an object from the byte[]). Once these methods are registered via PhotonPeer.RegisterType(), you can use objects of this class in events just like you tried. Check out CustomTypes.cs for some examples with Unity's classes like Vector3. Our library will then serialize your class but it will also prefix your byte[] with length- and type-info. All in all, your byte[] + 6 bytes will be sent for this class.
    • Transform the relevant information into a object[] or into hashtable on demand.
      For a small class like yours, the resulting overhead (in sent data) is quite high. Instead, you could probably just write the key-value pairs to the hashtable. Or use a single key and convert manyVars into a object[] of serializable (base) types.
  • Tobias wrote:
    Photon does not know how to serialize your class "someVars" in that case.

    You could solve this in two ways:
    • Implement and register custom type serialization methods.
      In this case, you would implement two methods: one that writes this class into a byte[] and one that creates an object from the byte[]). Once these methods are registered via PhotonPeer.RegisterType(), you can use objects of this class in events just like you tried. Check out CustomTypes.cs for some examples with Unity's classes like Vector3. Our library will then serialize your class but it will also prefix your byte[] with length- and type-info. All in all, your byte[] + 6 bytes will be sent for this class.
    • Transform the relevant information into a object[] or into hashtable on demand.
      For a small class like yours, the resulting overhead (in sent data) is quite high. Instead, you could probably just write the key-value pairs to the hashtable. Or use a single key and convert manyVars into a object[] of serializable (base) types.


    Ok I see, thanks for information!