Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm getting a strange behavior here - when i create a simple C# script which holds an Array of classes, where both, the script class and the array classes, are marked as Serializable, my sceneview starts lagging on moving the mouse (when the gameobject, which contains the script component is selected). Also, the lag increases, when the array class has more members, which are marked as SerializeField.

If i add the attribute [field: NonSerialized] over my array, the lag is gone. Also, [HideInInspector] doesn't change a thing - it looks to me like something is causing unity to serialize the script content every frame - which would be a little bit strange, because what should cause such a behavior?

Does somebody know a solution for this?

[Edit: Code Snippet]

using System;
using UnityEngine;

[Serializable]
public class TestObject{
    public int              IndexX;
    public int              IndexY;
    public int              LengthX;
    public int              LengthY;
    public float            AnimationLength;
    public bool             Animate;
    public float            AnimationSpeed;



    [SerializeField]
    private GameObject      mGameObject;

}


[Serializable]
public class TestScript{

  [HideInInspector]
  public TestObject[] Objects       = new TestObject[256*64];

  void Start(){

  }

  void Update(){

  }

}

This very short and basic script causes lagging issues... but an array of 256x64 should not be that hard to serialize. I'm building a Jump'n'Run game - and i would be very happy to get messages like "OnSerialize" and "OnDeserialize", so i could save and reload my tiles in a simplier format, unity saves the tiles gameobjecs, its meshes an stuff - but thats a heavy overload.. tried to make something like this, with two lists and listening for the "awake" message - but if i get the message in the editor, i can not delete the existing gameobjects - it would be nice, if i could delete and recreate them, when the editor reloads the data.

share|improve this question

put on hold as off-topic by Josh Petrie Dec 22 at 19:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
256*64 is a lot of elements (over 16,000). Do you need to initialize the array right there or can you do it in Awake or Start? Does that make the problem go away? –  Tetrad Feb 12 '13 at 17:13
    
Does this happen only in the Editor or in the Standalone Player too? –  Marcin Seredynski Feb 13 '13 at 14:10
    
Happens only in Edit Mode, the Game just runs fine. Maybe the UnityEditor checks my array at runtime for changes.. or something.. –  Denis Germ Feb 15 '13 at 19:08

Browse other questions tagged or ask your own question.