So here’s a weird one: I have this very simple class called script. It has 2 boolArrays. One 2D and another 1D array.
using UnityEngine;
public class Script : MonoBehaviour {
public bool[,] boolArray2D = new bool[10,10];
public bool[] boolArray1D = new bool[10];
}
I also have this Custom Editor Script which is supposed to modify the 2 arrays.
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Script))]
public class CustomScriptInscpector : Editor {
Script targetScript;
void OnEnable(){
targetScript = target as Script;
}
public override void OnInspectorGUI(){
EditorGUILayout.BeginHorizontal ();
for (int y = 0; y < 10; y++) {
EditorGUILayout.BeginVertical ();
for (int x = 0; x < 10; x++) {
targetScript.boolArray2D [x,y] = EditorGUILayout.Toggle (targetScript.boolArray2D [x,y]);
}
EditorGUILayout.EndVertical ();
}
EditorGUILayout.EndHorizontal ();
EditorGUILayout.Space ();
for (int x = 0; x < 10; x++) {
targetScript.boolArray1D [x] = EditorGUILayout.Toggle (targetScript.boolArray1D [x]);
}
}
}
This is what it looks like:
It’s super super basic, but here is the problem: When entering play mode, changes I made to the 2D-array in the custom inspector disappear and changes to the one dimensional stay there.
Is this a bug or am I just stupid?
( I shouldn’t need to mark anything as Serializable because everything is public and standardt-types. I also tried several approaches, with
if(GUI.changed && !Application.isPlaying){
EditorUtility.SetDirty(targetScript);
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
but to no avail ): )
Any help is appreciated!