Sending array of custom types via PlayerCustomProperties, cannot deserialise from other players

Options

I have an InventoryEntry Class which has 2 bytes, and which I have implemented Serialize and Deserialize, plus registered the type, all working fine when running through OnPhotonSerializeView.

When I LocalPlayer.SetCustomProperties with an array of these as an entry keyed by a string, it works fine locally, however I cannot process entries from other players.

This seems to be something with the cast - the local player which has set the properties understands that it is fine, however when received from elsewhere, while it has the correct type attached it cannot cast to an array of the type.

I get the impression it is trying to cast to an item of the type (e.g. 2 bytes) rather than an array. Do I need to create a new serialiser/deserialiser (in which case what signature are these methods looking for) or create a class which holds an array of my custom type and a serialiser/deserialiser for this? Or?

Many thanks

Best Answers

  • opposable
    opposable
    Answer ✓
    Options

    Ah - the problem was that I was registering the Type serilialsation just before parsign the received player settings, however the settings had been received and parsed before then, at a point before the converter was registered. For anyone in future, register your converters before you connect in to PUN> I'm sure the documentation mentions this somewhere now I think about it.

  • Tobias
    Tobias admin
    Answer ✓
    Options

Answers

  • opposable
    opposable
    edited May 2022
    Options

    I have managed to resolve by converting the received type, if unknown I.e. not set in local players hashtable) into a Photon.UnknownType and passing the data field into the existing deserializer, but this feels like I'm bending the API a bit. Be good to know the recommended best practice.

  • opposable
    Options

    I have tried serirliasing with stream buffers, serilisaing as a dictionary, serialising as a hashtable - whatever I do, if a player properties hashtable is received I cannot find a way for it to understand it is of the custom type I have registered, only an Unknown type - what am I missing?

  • opposable
    opposable
    Answer ✓
    Options

    Ah - the problem was that I was registering the Type serilialsation just before parsign the received player settings, however the settings had been received and parsed before then, at a point before the converter was registered. For anyone in future, register your converters before you connect in to PUN> I'm sure the documentation mentions this somewhere now I think about it.

  • Tobias
    Tobias admin
    Answer ✓
    Options