Hey there,
So Ive been fighting with this kind of problem for a while now. It seems to come and disappear with no clear reason.
The arrays in my game (which I edit in the editor) sometimes serialize and sometimes not. They are always public, sometimes unity or c# native types and sometimes custom types by me.
Here is a little example:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class Mapbuilder : BaseClass
{
public int[] stateProbs;
}
I edit this script here:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class Window_MapBuilder : EditorWindow
{
private int width{ get { return Screen.width; } }
private int height{ get { return Screen.height - 22; } }
private Mapbuilder builder;
[MenuItem ("Custom/MapBuilder")]
private static void Init ()
{
EditorWindow.GetWindow<Window_MapBuilder> ().Show ();
}
void Update ()
{
Repaint ();
}
void OnGUI ()
{
Undo.RecordObject ((Object)this, "Edit Builder Window");
if (builder == null) {
builder = FindObjectOfType<Mapbuilder> ();
}
minSize = new Vector2 (500, 400);
if (builder.stateProbs == null || builder.stateProbs.Length != 5)
builder.stateProbs = new int[5];
for (int i = 0; i < 5; i++) {
builder.stateProbs <em>= EditorGUI.IntSlider (new Rect (10, sy, w - 40, 20), MapObjects.Tree.TreeObject.growStates _+ ":", builder.stateProbs *, 0, 100);*_</em>
* sy += 30;*
* }*
* EditorUtility.SetDirty (builder);*
* }*
I have cut down the scripts to only the parts that seem important. If you want full ones just tell me.
Now: I can edit the array in my window and it also saves for when I hit play. It does however reset when I close Unity. A similar thing happens with an array of a custom class I made. Only that this one does not get reset completely but rather reverted to a state it had two days ago.
As you can see I already tried things like SetDirty e.g.
Now Im fresh out of ideas. You got any?
Help would be appreciated
EDIT: I should mention that Baseclass, which Mapbuilder inherits from, inherits from Monobehaviour, so Mapbuilder is basecally a Monobehaviour.