I’m building an editor component and have run into a real snag - when creating Texture2D’s dynamically they do not appear to support serialization. I’ve tried following the directions at: Unity Serialization | Unity Blog and this works if and only if I replace the MakeTexture() call with EditorGUIUtility.whiteTexture - which is a Texture2D! So something is happening under the covers here and I’m not sure what.
My question - what can I do to ensure a created texture is serialized properly so that it stays around between runs?
using System;
using UnityEditor;
using UnityEngine;
[Serializable]
public class TestSer
{
[SerializeField]
public string m_Name;
[SerializeField]
private int m_Value;
[SerializeField]
public Texture2D m_Texture;
public TestSer ()
{
m_Name = "chris";
m_Value = 5;
m_Texture = MakeTexture( Color.red );
}
private Texture2D MakeTexture( Color col )
{
Texture2D result = new Texture2D( 1, 1 );
result.SetPixels( new Color[ ] { col } );
result.Apply();
return result;
}
}