I am currently making a custom editor and as i add more data, the editor start to get really slow. So i made a simple example to show this problem:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Example))]
public class ExampleEditor : Editor
{
public override void OnInspectorGUI()
{
EditorGUILayout.LabelField("Data size: " + (target as Example).data.vector.Length);
if (GUILayout.Button("Create data"))
{
(target as Example).CreateData();
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Example : MonoBehaviour {
public ExampleData data = new ExampleData();
public void CreateData()
{
int size = 1000;
data = new ExampleData();
data.vector = new ExampleDataInto[size];
for(int i = 0; i < size; i++)
{
data.vector[i] = new ExampleDataInto();
}
}
}
[System.Serializable]
public class ExampleData
{
public ExampleDataInto[] vector = new ExampleDataInto[0];
}
[System.Serializable]
public class ExampleDataInto
{
public Vector3[] vector = new Vector3[1000];
public Vector3[] vector2 = new Vector3[1000];
public Vector3[] vector3 = new Vector3[1000];
}
Just keep adding into ExampleDataInto the vars vector4, vector5, vector6, etc… each one add more slowdown to the editor;
So i changed the ExampleDataInto to extend ScriptableObject
using UnityEngine;
public class Example : MonoBehaviour {
public ExampleData data = new ExampleData();
public void CreateData()
{
int size = 1000;
data = new ExampleData();
data.vector = new ExampleDataInto[size];
for(int i = 0; i < size; i++)
{
data.vector[i] = ScriptableObject.CreateInstance<ExampleDataInto>();
}
}
}
[System.Serializable]
public class ExampleData
{
public ExampleDataInto[] vector = new ExampleDataInto[0];
}
[System.Serializable]
public class ExampleDataInto:ScriptableObject
{
public Vector3[] vector = new Vector3[1000];
public Vector3[] vector2 = new Vector3[1000];
public Vector3[] vector3 = new Vector3[1000];
}
This way the editor don’t lag, but once i hit play it throw this error:
Does anyone know the corret way to set this up?