Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

[Solved] Serialization error at runtime

Discussion in 'Windows' started by demonixis, Jul 5, 2014.

  1. demonixis

    demonixis

    Joined:
    Aug 20, 2013
    Posts:
    185
    Hi,

    When I deploy my game to Windows Store profil, I've a serialization error and this message :

    A script behaviour has a different serialization layout when loading. (Read 24 bytes but expected 76 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?

    (Filename: C:/BuildAgent/work/d63dfc6385190b60/Runtime/Serialize/SerializedFile.cpp Line: 1170)

    I readed a lot of post about this problem which seems to be old.

    I tryied some tricks such as remove the Library folder, rebuild le project, etc...

    What can I do to solve this problem ?

    I think that is maybe my code, I'm using inheritance of MonoBehavior and polymorphism and maybe it's that the problem ?

    This is a typical piece of code that I use :

    Code (CSharp):
    1.  
    2. // Class BasePlayer
    3.  
    4. public class BasePlayer : MonoBehaviour
    5. {
    6.     public int health = 100;
    7.     public int maxHealth = 100;
    8.     public int shieldValue = 25;
    9.     public int attackValue = 25;
    10.     public float luck = 1.0f;
    11.     protected Transform _transform;
    12. }
    13.  
    14. // Class BaseFIghter
    15.  
    16. [RequireComponent(typeof(BasePlayer))]
    17. public class BaseFighter : MonoBehaviour
    18. {
    19.     public const int ScoreToEscape = 9;
    20.  
    21.     public enum CombatActions
    22.     {
    23.         None = 0, Attack, Defend, Escape
    24.     }
    25.  
    26.     protected BasePlayer _basePlayer;
    27.     protected Transform _transform;
    28.     private BaseFighter _target;
    29.  
    30.     // Some code without preprocessor
    31. }
    32.  
    33. // Class MazeMonsterFighter
    34.  
    35. [RequireComponent(typeof(MazeMonster))]
    36. public class MazeMonsterFighter : BaseFighter
    37. {
    38.     // Some code again
    39. }
    40.  
    41. // Class MazePlayerFighter
    42.  
    43. public class MazePlayerFighter : BaseFighter
    44. {
    45.     // Some code again
    46. }
    The problem is maybe because BaseFighter contains references to Base class ?

    I have this problem ONLY with Windows Store Apps, all works well on Windows classic, Mac, Web, Windows Phone 8 and Android.



    Thanks for the help !

    Yann.
     
    Last edited: Jul 5, 2014
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,956
    Is this 4.5?
     
  3. demonixis

    demonixis

    Joined:
    Aug 20, 2013
    Posts:
    185
    Hi,

    Yes my version of Unity is 4.5.1 f 3.

    After a new debug session I've discovered that it's not my player scripts that cause this problem but apparently it's a part of my UI. I'm using NGUI.

    Edit: I solved this problem by renaming some of my GameObjects.
     
    Last edited: Jul 5, 2014
  4. Iamdain

    Iamdain

    Joined:
    Feb 3, 2010
    Posts:
    90
    @demonixis could you explain what you did in renaming GO's and what about the names caused the problem? We're experiencing a similar issue...
     
  5. demonixis

    demonixis

    Joined:
    Aug 20, 2013
    Posts:
    185
    It seems to be solved with latest versions of Unity