Quantcast
Channel: Recent Discussions — Photon Engine
Viewing all articles
Browse latest Browse all 15755

How to serialize a custom class to send to clients via RPC?

$
0
0
Each player has a PlayerControl class, and I want every client in a room to have each player's instance of their PlayerControl class. This will allow the game's GameRules class to send RPC's and affect the values of each player's PlayerControl class. I want to send the PlayerControl via RPC when starting the game, but I don't know how.

I have looked at forum posts from many years ago and also studied the CustomTypes.cs script. At first I followed the answer in https://forum.unity3d.com/threads/pun-serialization.405031/ , marked my PlayerControl class as serializable, and used my newly created Serialize and Deserialize functions, but came up with an error.

I'd like to try out the CustomTypes.cs method of serializing a custom class and registering the type as it seems more straight forward. Anyone have any tips on how to convert the examples in CustomTypes.cs to allow serializing a custom class? In the custom type examples, they are mostly dealing with float values when serializing Vectors and quaternions. How would it be different if I wanted a custom class to be serialized? I appreciate the help in advance.

Viewing all articles
Browse latest Browse all 15755

Trending Articles