Error occurs when using abstract class for sharedVariable


New member
public class TestSharedObject : SharedVariable<TestAbstractClass>

public abstract class TestAbstractClass{

MissingMethodException: Method 'Cannot create an abstract class '{0}'..Test.TestAbstractClass' not found.
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic, System.Boolean wrapExceptions) (at <f646c7a159d243a7909d5204af0f0c56>:0)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean wrapExceptions, System.Boolean skipCheckThis, System.Boolean fillCache) (at <f646c7a159d243a7909d5204af0f0c56>:0)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Boolean wrapExceptions, System.Threading.StackCrawlMark& stackMark) (at <f646c7a159d243a7909d5204af0f0c56>:0)
System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic, System.Boolean wrapExceptions) (at <f646c7a159d243a7909d5204af0f0c56>:0)
System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) (at <f646c7a159d243a7909d5204af0f0c56>:0)
BehaviorDesigner.Editor.FieldInspector.DrawSingleField (BehaviorDesigner.Runtime.Tasks.Task task, UnityEngine.GUIContent guiContent, System.Reflection.FieldInfo fieldInfo, System.Type fieldType, System.Object value) (at <d6203e70841f4bfeb69e5def378a2bc0>:0)
BehaviorDesigner.Editor.FieldInspector.rawSingleField(Task, GUIContent, FieldInfo, Type, Object)
BehaviorDesigner.Editor.FieldInspector.rawField(Task, GUIContent, FieldInfo, Type, Object)
BehaviorDesigner.Editor.FieldInspector.rawField(Task, GUIContent, FieldInfo, Object)
BehaviorDesigner.Editor.FieldInspector.rawFields(Task, Object, GUIContent)
BehaviorDesigner.Editor.VariableInspector.rawSharedVariable(IVariableSource, SharedVariable, Boolean)
BehaviorDesigner.Editor.VariableInspector.rawAllVariables(Boolean, IVariableSource, List`1&, Boolean, List`1&, Int32&, String&, Int32&, Boolean, Boolean)
BehaviorDesigner.Editor.BehaviorInspector.rawInspectorGUI(Behavior, SerializedObject, Boolean, Boolean&, Boolean&, Boolean&)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions() (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorApplication.cs:362)
What would you expect to be displayed within the editor for an abstract class? In that case the editor cannot create an instance of it so you are getting an error.
It runs well in the runtime as I've assigned a object to the Value of shared variable myself with BehaviorTree.GetVariable(); So I think the error logs should not be displayed within the editor. Here is another problem which is related to it: the error logs would be outputted If I've chosen the prefab which contains the component of behavior tree then enter the play mode or no error log would be displayed
As for the content of the abstract class, I think showing a empty of class at the editor is fine to me. in fact it even did not show the name of abstract class while I'm editing the behavior tree in the tab of Variable

Screenshot 2023-11-08 at 6.42.18 PM.png
That makes sense. I'll make this change and send you an updated version.
Found a similar problem, if a shared class has no default constructor, it will output an error and show nothing when I open the editor. I think it should not output error since I will assign the shared variable reference at runtime.

public class SharedABC : SharedVariable<ABC>

public class ABC
public ABC(int[] abc){}
Variables are created with Activator.CreateInstance and it does require you to have a default constructor. If you add a constructor without any parameters it'll work.
That's what I'm currently doing and it works. But I prefer it does not output this error thus I can remove the default constructor since it is kind of like the abstract class: if you can not create it with default constructor then just ignore it and show a empty content in the editor. Though it is not urgent since I have added the default constructor as a work around solution.