abstract class

Discussion and help for Easy Save 3
Post Reply
God Bao
Posts: 1
Joined: Sat May 15, 2021 3:16 am

abstract class

Post 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)

User avatar
Joel
Moodkie Staff
Posts: 3526
Joined: Wed Nov 07, 2012 10:32 pm

Re: abstract class

Post 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
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

User avatar
Joel
Moodkie Staff
Posts: 3526
Joined: Wed Nov 07, 2012 10:32 pm

Re: abstract class

Post 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
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

Post Reply