- Home /
Sceneview Lags when using Arrays
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.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to control serialized variables over the inspector pane? 1 Answer