playMaker

Author Topic: Playmaker serialization issue  (Read 214 times)

allender

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Playmaker serialization issue
« on: May 28, 2019, 02:25:56 PM »
We have something like this:

Code: [Select]
        public enum HintStatus : byte
        {
            Inactive,
            Active,
            Complete,
            Failed,
            Hidden
        }

and in a custom playmaker action, we do something like this:

Code: [Select]
    public class HintAction : FsmStateAction
    {
        public HintStatus hintStatus;

    }

The fact that the enum is serialized into a byte causes all kind of issues with playmaker.  I'll include a snippet below.  Essentially you can add one of these actions to a state, save the thing (prefab or scene), go to a different playmaker SM, then back to the one you just saved with this byte enum.  Selecting the state onto which the action was added causes these issues.  I tried to boil this issue down to something simple given IP restrictions.  I can provide more info if needed.

Once this happens, the playermaker editor window doesn't seem to work for any state machines.  A restart of Unity is required.

Sample of errors:
Code: [Select]
InvalidCastException: Specified cast is not valid.
HutongGames.PlayMaker.ActionData.SaveActionField (HutongGames.PlayMaker.Fsm fsm, System.Type fieldType, System.Object obj) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionData.cs:3081)
HutongGames.PlayMaker.ActionData.SaveAction (HutongGames.PlayMaker.Fsm fsm, HutongGames.PlayMaker.FsmStateAction action) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionData.cs:2677)
HutongGames.PlayMaker.ActionData.SaveActions (HutongGames.PlayMaker.FsmState state, HutongGames.PlayMaker.FsmStateAction[] actions) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionData.cs:2648)
HutongGames.PlayMaker.FsmState.SaveActions () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:130)
HutongGames.PlayMakerEditor.FsmEditor.SaveActions (HutongGames.PlayMaker.FsmState state, System.Boolean errorCheck) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmEditor.cs:1988)
HutongGames.PlayMakerEditor.FsmBuilder.AddAction (HutongGames.PlayMaker.FsmState state, System.Type actionType) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmBuilder.cs:1258)
HutongGames.PlayMakerEditor.EditorCommands.AddAction (HutongGames.PlayMaker.FsmState state, System.Type actionType) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/EditorCommands.cs:99)
HutongGames.PlayMakerEditor.StateInspector.AddActionBeforeSelectedAction (System.Type actionType) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/StateInspector.cs:2136)
HutongGames.PlayMakerEditor.StateInspector.AddAction (System.Type actionType) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/StateInspector.cs:2098)
HutongGames.PlayMakerEditor.ActionSelector.AddSelectedActionToState () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/ActionSelector.cs:998)
HutongGames.PlayMakerEditor.ActionSelector.DoActionButton (System.String category, System.Type actionType) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/ActionSelector.cs:545)
HutongGames.PlayMakerEditor.ActionSelector.DoFilteredActionList () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/ActionSelector.cs:358)
HutongGames.PlayMakerEditor.ActionSelector.DoActionList () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/ActionSelector.cs:322)
HutongGames.PlayMakerEditor.ActionSelector.DoGUI () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/ActionSelector.cs:180)
HutongGames.PlayMakerEditor.BaseEditorWindow.OnGUI () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/BaseEditorWindow.cs:117)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/projects/unity_release/Editor/Mono/HostView.cs:342)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/projects/unity_release/Editor/Mono/HostView.cs:336)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at C:/projects/unity_release/Editor/Mono/HostView.cs:310)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect, System.Boolean customBorder, System.Boolean floatingWindow, System.Boolean isBottomTab) (at C:/projects/unity_release/Editor/Mono/GUI/DockArea.cs:361)
UnityEditor.DockArea.OldOnGUI () (at C:/projects/unity_release/Editor/Mono/GUI/DockArea.cs:320)
UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout) (at C:/projects/unity_release/Modules/UIElements/IMGUIContainer.cs:266)
UnityEngine.Experimental.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect) (at C:/projects/unity_release/Modules/UIElements/IMGUIContainer.cs:438)
UnityEngine.Experimental.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e) (at C:/projects/unity_release/Modules/UIElements/IMGUIContainer.cs:421)
UnityEngine.Experimental.UIElements.IMGUIContainer.HandleEvent (UnityEngine.Experimental.UIElements.EventBase evt) (at C:/projects/unity_release/Modules/UIElements/IMGUIContainer.cs:401)
UnityEngine.Experimental.UIElements.EventDispatcher.PropagateEvent (UnityEngine.Experimental.UIElements.EventBase evt) (at C:/projects/unity_release/Modules/UIElements/EventDispatcher.cs:754)
UnityEngine.Experimental.UIElements.EventDispatcher.ProcessEvent (UnityEngine.Experimental.UIElements.EventBase evt, UnityEngine.Experimental.UIElements.IPanel panel) (at C:/projects/unity_release/Modules/UIElements/EventDispatcher.cs:599)
UnityEngine.Experimental.UIElements.EventDispatcher.Dispatch (UnityEngine.Experimental.UIElements.EventBase evt, UnityEngine.Experimental.UIElements.IPanel panel, UnityEngine.Experimental.UIElements.DispatchMode dispatchMode) (at C:/projects/unity_release/Modules/UIElements/EventDispatcher.cs:307)
UnityEngine.Experimental.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.Experimental.UIElements.EventBase e, UnityEngine.Experimental.UIElements.DispatchMode dispatchMode) (at C:/projects/unity_release/Modules/UIElements/Panel.cs:176)
UnityEngine.Experimental.UIElements.UIElementsUtility.DoDispatch (UnityEngine.Experimental.UIElements.BaseVisualElementPanel panel) (at C:/projects/unity_release/Modules/UIElements/UIElementsUtility.cs:245)
UnityEngine.Experimental.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/projects/unity_release/Modules/UIElements/UIElementsUtility.cs:68)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/projects/unity_release/Modules/IMGUI/GUIUtility.cs:179)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3629
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Playmaker serialization issue
« Reply #1 on: May 28, 2019, 11:09:13 PM »
Thanks for reporting this. Will investigate and get a fix into the next update...

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3629
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Playmaker serialization issue
« Reply #2 on: May 29, 2019, 05:12:17 PM »
Okay, I could repro here. Fix will be in the next update.

As a workaround, for now, you can use an FsmEnum variable:

Code: [Select]
[ObjectType(typeof(HintStatus))]
public FsmEnum hintStatus;

This handles the byte backing field properly (and gives you the flexibility to use a variable for the action parameter).
« Last Edit: May 29, 2019, 05:15:11 PM by Alex Chouls »

allender

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Playmaker serialization issue
« Reply #3 on: May 29, 2019, 06:26:51 PM »
Great.  Thanks for the workaround as well.