NodeCanvas Forums › Support › SetEnum node becoming broken when bound to global BB
We made an unfortunate arrangement that broke the Node editor (i.e. we can no longer edit the node in question because of the exceptions):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
MissingMethodException: Cannot create an abstract class 'System.Enum'. System.Activator.CheckAbstractType (System.Type type) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Activator.cs:392) System.Activator.CreateInstance (System.Type type, Boolean nonPublic) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Activator.cs:348) System.Activator.CreateInstance (System.Type type) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Activator.cs:254) NodeCanvas.Framework.Variable+<GetGetConverter>c__AnonStorey0.<>m__1 () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/Variable.cs:107) NodeCanvas.Framework.BBParameter'1+<BindGetter>c__AnonStorey0[System.Object].<>m__0 () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:429) NodeCanvas.Framework.BBParameter'1[T].get_value () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:362) NodeCanvas.Framework.BBParameter'1[T].get_objectValue () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:399) NodeCanvas.Framework.BBParameter.get_isNull () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Runtime/Variables/BBParameter.cs:244) ParadoxNotion.Design.EditorUtils.GenericField (System.String name, System.Object value, System.Type t, System.Reflection.MemberInfo member, System.Object context) (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/_Commons/Design/PartialEditor/EditorUtils/EditorUtils_GUI.cs:171) ParadoxNotion.Design.EditorUtils.ShowAutoEditorGUI (System.Object o) (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/_Commons/Design/PartialEditor/EditorUtils/EditorUtils_GUI.cs:119) NodeCanvas.Framework.Task.DrawDefaultInspector () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Design/PartialEditor/EDITOR_Task.cs:103) NodeCanvas.Tasks.Actions.SetEnum.OnTaskInspectorGUI () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Tasks/Actions/Blackboard/SetEnum.cs:32) NodeCanvas.Framework.Task.ShowTaskInspectorGUI (NodeCanvas.Framework.Task task, System.Action'1 callback, Boolean showTitlebar) (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Design/PartialEditor/EDITOR_Task.cs:67) ParadoxNotion.Design.EditorUtils.TaskField (NodeCanvas.Framework.Task task, ITaskSystem ownerSystem, System.Type baseType, System.Action'1 callback) (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/_Commons/Design/PartialEditor/EditorUtils/EditorUtils_TaskFieldEditor.cs:44) NodeCanvas.Framework.Node.TaskAssignableGUI () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Design/PartialEditor/EDITOR_Node.cs:688) NodeCanvas.Framework.Node.ShowNodeInspectorGUI () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Design/PartialEditor/EDITOR_Node.cs:663) NodeCanvas.Framework.Graph.ShowInspectorGUIPanel (UnityEngine.Event e, Vector2 canvasMousePos) (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Design/PartialEditor/EDITOR_Graph.cs:471) NodeCanvas.Framework.Graph.ShowGraphControls (UnityEngine.Event e, Vector2 canvasMousePos) (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Design/PartialEditor/EDITOR_Graph.cs:139) NodeCanvas.Editor.GraphEditor.OnGUI () (at Assets/External/Plugins/ParadoxNotion/NodeCanvas/Framework/Design/Editor/Windows/GraphEditor.cs:459) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222) |
The BBParameter on SetNode is bound to a global blackboard variable, which itself is bound to a field on a component (which is NOT an enum type, but something other, DateTime if I remember correctly).
The Canvas editor looks good until I instantiate the global blackboard into the scene, at which time the BB parameters on the graph get bound to that blackboard and then the type mismatches start throwing those exceptions. I have no idea why the DateTime variable could be chosen for a Enum-type parameter at first.
Hey,
Thanks for the report. I was able to reproduce the problem and found the cause. To fix this, please open up Variable.cs and in method named GetGetConverter, replace the check code in lines 106-110 with the following:
1 2 3 4 5 6 7 8 |
//convertible to convertible if (toType.RTIsValueType() && varType.RTIsValueType()){ if (typeof(IConvertible).RTIsAssignableFrom(toType) && typeof(IConvertible).RTIsAssignableFrom(varType)){ return ()=> { return Convert.ChangeType(value, toType); }; } } |
Let me know if it works for you.
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh
Looks like it works, the exceptions are gone and I can edit the node again! Thanks for the quick fix!
Okay I think the fix broke other parts in our FSMs that previously worked. E.g. there was a SendEvent<string> Action where the EventValue type was not a string, but an integer. That worked previously but after applying the fix the receiver just gets NULL as the string parameter from the event.
Inspector should warn in such cases at least.
For now it seems we have too many places where it already works without the hotfix, but with the hotfix, everything gets broken 😉
Hey,
Sorry about that. It was a wrong fix on my part because it excluded string auto conversions. Please replace the code once again with this temporary fix (I will fix this better in release):
1 2 3 4 5 6 |
//convertible to convertible if (typeof(IConvertible).RTIsAssignableFrom(toType) && typeof(IConvertible).RTIsAssignableFrom(varType)){ return ()=> { try {return Convert.ChangeType(value, toType);} catch {return !toType.RTIsAbstract()? Activator.CreateInstance(toType) : null;} }; } |
Please let me know if everything works correctly this time.
Thank you.
Join us on Discord: https://discord.gg/97q2Rjh