Set Object data on all clients on Load

Options
Sorry for another post so soon, but I'm having real trouble extrapolating the basic concepts talked about in the RPC tutorial to my game.

In my game, players control a group of units. These units have certain stats (Speed, health) etc, but the stats across clients are not showing. For example I build the game, join the room etc, my units spawn, great. BUT, when I add another player from the editor, the editor is telling me that the OTHER players units stats are all 0 (the stats are built once the Unit is loaded into the game, since it needs other data first before determining the Total unit speed, etc.).

From what I understand, I need to RPC these stats to the other clients. For the moment, I ONLY want to receive these stats on loading into the game, Ill worry later about updating them as the game plays out. So, Photon View is observing my Unit_Status script, which is what updates its position, rotation etc to the server. All that works just fine. But how can I pass its stats (Speed, Health) to other clients, since the other client won't know these stats before joining the game??


TLDR: My units are getting passed info about themselves at Instatiation. This info is correctly getting read. However, I need to access this same info about that unit on all clients. In the inspector view of 2nd client, the public stats of the other player's units are reading as '0'. How do I give this info to the unit, as well as its info to other clients?

Comments

  • After some more research, it seems I need to make my class serializable, and convert it to bits, then pass that on instantiation and reconvert bits to my class. Am I on the right track here/Any tips where to get good examples of this?
  • Ok so after a lot of research, Im stuck on the last step.

    http://doc.exitgames.com/en/onpremise/c ... stq=&stp=0

    says "For any type not listed above, Photon will need your help to de/serialize important values.

    The basic idea is that you write two methods to convert your class to a byte-array and back, then register those with the Photon API. When that's done you can include instances of that type in any message you send. "


    **So far so good, but I could REALLY use some help solving this issue. Any examples of someone doing this process on the internet? Ive not been able to find any, and have spent DAYS trying to sort through this by myself.

    For example where do I put "Protocol.TryRegisterCustomType(typeof(MyCustomType), myCustomTypeCode, MyCustomType.Serialize, MyCustomType.Deserialize);" that line, and what libraries do I need to be using? As it stands, monodevelop is telling me "the name Protocol doesn't exist in the current context". PLEASE HELP
  • Tobias
    Options
    I'm sorry to read you're stuck.
    You are on the right track. You need to make your own class serializable and for that, you need to write 2 methods and "register" them.
    There is no good doc especially for this but you should be able to derive your solution from the file CustomTypes.cs in the PUN package. It implements several Unity types as Custom Type and registers them. Use this as blueprint and write your values to the stream as needed.

    Let me know if you're stuck still. Maybe I can write more tomorrow.
  • Thanks so much for your reply! Ive just been sending all the data via separate RPC calls, but now that I have a few examples I can probably work out how to do this, when I do, Ill be sure to post the solution, thanks again for your help!