Page 1 of 1

abstract class

Posted: Sat May 15, 2021 7:37 am
by God Bao

Code: Select all

using System;
using UnityEngine;

[Serializable]
public class TestMono :MonoBehaviour
{
	public AbsMessage child;
}

[Serializable]
public abstract class AbsMessage 
{
	public AbsMessage() { }
	public abstract int Msg { get; set; }
}

[Serializable]
public class Message : AbsMessage
{
	public Message() : base() { }
	public override int Msg { get => _msg; set => _msg = value; }
	private int _msg;
}
I have a game object with a testmono component. When I save the game object, there is no error in the above code, but why can't I load it.

Error:
MissingMethodException: Cannot create an abstract class 'AbsMessage'.
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Activator.CreateInstance (System.Type type) (at <695d1cc93cca45069c528c15c9fdd749>:0)
ES3Internal.ES3Reflection.CreateInstance (System.Type type) (at Assets/Plugins/Easy Save 3/Scripts/ES3Reflection.cs:254)

Re: abstract class

Posted: Sat May 15, 2021 9:07 am
by Joel
Hi there,

Please could you replicate this in a new project with a simple scene and send it to me? I don't appear to be able to replicate this at my end.

All the best,
Joel

Re: abstract class

Posted: Sun May 16, 2021 9:11 am
by Joel
Thanks for sending that over.

The issue is that the ES3Type only has access to the type of the object being saved at runtime, not the field type. I've created a version of Easy Save which will use the field type when creating the ES3Type (you'll need to reset your ES3Types to default from the Types window and regenerate them).

If you private message me your invoice number I'll send over this update right away.

All the best,
Joel