type mismatch on texture 2D inside scriptable object
Hi I have a scriptable object with a texture2D inside it that is marked as serialized field, now, on creation of this scriptable object, i call a method in it to initialize it and inside that method, i assign the icon (the texture 2D) by reading a static readonly texture 2D on my resources class. when i look at the scriptable object in inspector, the icon shows type mismatch and when i close unity and re run it, the icon is not being serialized. here is code snippets for this :
first the scriptable object itself :
[Serializable] public partial class NodeSchema : ScriptableObject, ISerializationCallbackReceiver
{
[SerializeField] protected Texture2D Icon;
}
then the initialize method :
public class TestNodeSchema : Common.Editor.Graph.NodeSchema
{
public override void Initialize()
{
base.Initialize();
Icon = Resource.TestNode;
}
}
and finally the resources class. keep in mind there is an extension method that accepts a string and loads a texture 2D from the resources i added to the dll library. when i add the scriptable object, the resource loads correctly first but i get the type mismatch, then on re running unity, the field becomes empty indicating that the texture is not being serialized properly.
public static class Resource
{
public static Texture2D TestNode = "Test".LoadTexture();
}
What am i missing here?
I'm also searching for a solution. I've got a hint that types in external dlls might not be properly serializeable. Did you tested it with NodeSchema not being in a dll?
Did you ever figure it out? @Jiraiyah I found out that by saving the asset the reference shows up, but I'd like to avoid this if possible.