Hi all.
Going batty with this one.
Scriptable Objects in a generic list are loosing object references on the 2nd serialization round tip.
Sample code:
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class DataClass : ScriptableObject
{
public string Data;
}
public class TestWindow : EditorWindow
{
[MenuItem("Window/Debug/Show Test Window")]
public static void OpenWindow()
{
//Open the window
TestWindow __window = EditorWindow.GetWindow<TestWindow>();
//Add some data
__window.DataList.Add(ScriptableObject.CreateInstance<DataClass>());
__window.DataList.Add(ScriptableObject.CreateInstance<DataClass>());
}
public List<DataClass> DataList = new List<DataClass>();
void OnGUI()
{
foreach (var item in this.DataList)
{
item.Data = EditorGUILayout.TextField(item.Data, GUILayout.Width(300));
}
}
}
The behaviour I’m getting comes from:
- Open the window from the code above, 2 texts boxes will appear which I can enter some data into.
- Press the PIE Play button, window and data survives,
- Exit PIE, window and data survives
- Press PIE Play a second time, select the window to trigger OnGUI, both text boxes disappear and null object exceptions from line 31 will start spewing in the log.
I’ve just tested this on a fresh installation of 5.1.
I know there are other ways to achieve the result above, I was just wondering if anyone knows why this is failing this way.
A