Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by john_yarko · Aug 07, 2015 at 04:10 PM · networkserializationpun

[CLOSED]Problem with serialization after PUN update

After PUN update from 1.52 to 1.6 serialization stopped working. I'm getting exception "Exception: cannot serialize(): Run.Domain.NetworkPlayer..."

 public sealed class PhotonSerializableNetworkPlayer : INetworkSerializable
     {
 ...
 #region INetworkSerializable implementation
         public Byte[] Serialize(object customObject)
         {
             NetworkPlayer player = (NetworkPlayer)customObject;
             
             Int32 index = 0;
 
             Int16 nicknameLength = (Int16)player.Nickname.Length;
             Byte[] result = new Byte[sizeof(Int16) + nicknameLength + PhotonSerializableColor.ByteArraySize + 5 * sizeof(Byte)];
             
             Protocol.Serialize(nicknameLength, result, ref index);
             Byte[] nicknameBytes = Protocol.Serialize(player.Nickname);
             Buffer.BlockCopy(nicknameBytes, 0, result, index, nicknameBytes.Length);
             index += nicknameLength;
             
             Byte[] colorBytes = Protocol.Serialize(player.Color);
             Buffer.BlockCopy(colorBytes, 0, result, index, colorBytes.Length);
             index += colorBytes.Length;
             
             result[index++] = (player.IsReady) ? (Byte)1 : (Byte)0;
             
             return result;
         }
         
         public object Deserialize(Byte[] byteArray)
         {
             NetworkPlayer result = new NetworkPlayer();
             
             Int32 index = 0;
             
             Int16 nicknameLength;
             Protocol.Deserialize(out nicknameLength, byteArray, ref index);
             Byte[] nicknameBytes = new Byte[nicknameLength];
             Buffer.BlockCopy(byteArray, index, nicknameBytes, 0, nicknameLength);
             result.Nickname = (String)Protocol.Deserialize(nicknameBytes);
             index += nicknameLength;
 
             Byte[] colorBytes = new Byte[PhotonSerializableColor.ByteArraySize];
             Buffer.BlockCopy(byteArray, index, colorBytes, 0, PhotonSerializableColor.ByteArraySize);
             result.Color = (SerializableColor)Protocol.Deserialize(colorBytes);
             index += PhotonSerializableColor.ByteArraySize;
 
             result.IsReady = (byteArray[index++] == (Byte)1) ? true : false;
             
             return result;
         }
 #endregion

then I register delegates:

 {
 ...
       PhotonPeer.RegisterType(typeof(NetworkPlayer), (byte)'P', playerSerialization.Serialize, playerSerialization.Deserialize);
 ...
 }


Player's byte key is unique(i mean 'P', none of the other types uses it). What can be the problem? Unity 4.6.7 PUN 1.6

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by john_yarko · Aug 09, 2015 at 12:34 PM

Managed to find the problem. It was in byte-key, for some reason it was either used by some other type or smth else:) After changing it to e.g. 'L' everything started to work as intended.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by nogebatorr · Oct 01, 2016 at 08:50 PM

@john_yarko, I got the same problem when try to register my own type with byte 'P'. Then I found your post and try to use 'W' with the same result. Then I try 'Z' and 'A' - works good.

So I search in the project for the PhotonPeer.RegisterType call and found this snippet in Photon sources :)

 /// <summary>
 /// Internally used class, containing de/serialization methods for various Unity-specific classes.
 /// Adding those to the Photon serialization protocol allows you to send them in events, etc.
 /// </summary>
 internal static class CustomTypes
 {
     /// <summary>Register</summary>
     internal static void Register()
     {
         PhotonPeer.RegisterType(typeof(UnityEngine.Vector2), (byte)'W', SerializeVector2, DeserializeVector2);
         PhotonPeer.RegisterType(typeof(Vector3), (byte)'V', SerializeVector3, DeserializeVector3);
         PhotonPeer.RegisterType(typeof(Quaternion), (byte)'Q', SerializeQuaternion, DeserializeQuaternion);
         PhotonPeer.RegisterType(typeof(PhotonPlayer), (byte)'P', SerializePhotonPlayer, DeserializePhotonPlayer);
     }
 }

I think it could be necessary for Photon team to inform developers about this class here

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

stream layerweights onphotonserializeview 0 Answers

cant acces script bool on serialize view 0 Answers

On Click Event works only on Master Client. PUN 2 1 Answer

Why are NetworkWriter and NetworkReader methods not complementary? 1 Answer

Ping isDone allways false 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges