playMaker

Author Topic: Run FSM: InvalidCastException: Specified cast is not valid. [FIXED]  (Read 4417 times)

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
I have a FSM Template with an exposed string variable (like hostVariableName). I use 'Run FSM' with the template and use a variable (like float) with the convert option in the variable pulldown menu.

It gives "InvalidCastException: Specified cast is not valid." when I ran.

It's obviously easy to avoid, but it does come as a surprise and it's not super easy to find the problem unless you know that's the only thing you changed.
« Last Edit: February 08, 2021, 12:01:29 PM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #1 on: June 05, 2019, 01:09:48 AM »
Thanks for the report, I’ll see if I can repro here.
Can you copy/paste the full error.
Also what versions of Playmaker and Unity?

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #2 on: June 05, 2019, 08:09:07 AM »
Ah yes, sorry.
Unity 2018.3.12f1, Playmaker 1.9.0.p15 (and p7).
I was able to repro it in a new project.
Error is:
Code: [Select]
InvalidCastException: Specified cast is not valid.
HutongGames.PlayMaker.FsmVar.ApplyValueTo (HutongGames.PlayMaker.INamedVariable targetVariable) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmVariables/FsmVar.cs:671)
HutongGames.PlayMaker.FsmVarOverride.Apply (HutongGames.PlayMaker.FsmVariables variables) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/CustomActionTypes/FsmVarOverride.cs:33)
HutongGames.PlayMaker.FsmTemplateControl.ApplyOverrides (HutongGames.PlayMaker.Fsm overrideFsm) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/CustomActionTypes/FsmTemplateControl.cs:133)
HutongGames.PlayMaker.FsmTemplateControl.InstantiateFsm () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/CustomActionTypes/FsmTemplateControl.cs:73)
HutongGames.PlayMaker.Fsm.CreateSubFsm (HutongGames.PlayMaker.FsmTemplateControl templateControl) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1460)
HutongGames.PlayMaker.Actions.RunFSM.Awake () (at Assets/PlayMaker/Actions/StateMachine/RunFSM.cs:33)
HutongGames.PlayMaker.Fsm.Awake () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1650)
HutongGames.PlayMaker.Fsm.Init (UnityEngine.MonoBehaviour component) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1677)
PlayMakerFSM.Init () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:248)
PlayMakerFSM.Awake () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:210)

s0963123

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #3 on: January 28, 2021, 09:20:57 PM »
Sorry to bring up this old post. But I have very similar problem.
After setting up FSM Template with exposed variable, and run FSM.  The error log of "InvalidCastException: Specified cast is not valid." keep appear. And other game mechanism go wrongs as well.

I have already spent hours to troubleshoot it but in vain.
Roll back to a earlier version doesn't help either.

Could anyone point me in the right direction, on how to solve it? Or at least what goes wrong?

My unity version is 2019.1.14f1
My playmaker version is 1.9.0.p19

Quote
InvalidCastException: Specified cast is not valid.
HutongGames.PlayMaker.FsmVar.ApplyValueTo (HutongGames.PlayMaker.INamedVariable targetVariable) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmVariables/FsmVar.cs:674)
HutongGames.PlayMaker.FsmVarOverride.Apply (HutongGames.PlayMaker.FsmVariables variables) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/CustomActionTypes/FsmVarOverride.cs:33)
HutongGames.PlayMaker.FsmTemplateControl.ApplyOverrides (HutongGames.PlayMaker.Fsm overrideFsm) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/CustomActionTypes/FsmTemplateControl.cs:133)
HutongGames.PlayMaker.FsmTemplateControl.InstantiateFsm () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/CustomActionTypes/FsmTemplateControl.cs:73)
HutongGames.PlayMaker.Fsm.CreateSubFsm (HutongGames.PlayMaker.FsmTemplateControl templateControl) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1460)
HutongGames.PlayMaker.Actions.RunFSM.Awake () (at Assets/PlayMaker/Actions/StateMachine/RunFSM.cs:33)
HutongGames.PlayMaker.Fsm.Awake () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1650)
HutongGames.PlayMaker.Fsm.Init (UnityEngine.MonoBehaviour component) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1677)
PlayMakerFSM.Init () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:255)
PlayMakerFSM.Awake () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:210)

s0963123

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #4 on: January 28, 2021, 10:04:50 PM »
I finally manage to find out what goes wrong.

It appears to be some bug happened when you try to use a variable with the convert option in the variable pulldown menu in a 'Run FSM'.

Would it be fixed soon? Because it greatly hurdle how we could use template to streamline our production, which is one of the great features of playmaker.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #5 on: January 28, 2021, 10:26:10 PM »
Have you tried it in 1.9.1p1?

s0963123

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #6 on: January 29, 2021, 11:19:52 PM »
Still show the same error message in 1.9.1.p2.


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #7 on: January 29, 2021, 11:23:56 PM »
Ok, thanks for checking. I'll investigate.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #8 on: January 30, 2021, 06:16:06 PM »
This should be fixed in 1.9.1p3 currently in beta.
I've sent you an invite to the beta group if you have a chance to test it.

s0963123

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #9 on: January 31, 2021, 11:33:38 PM »
Thank you.

A bit off-topic:

I wonder how the output in the "run fsm" in version 1.9.1.p2 work?

It works really fine until I use "Next Frame Event" inside the template and change the value of certain variable(seems the type doesn't matter), then the output function seems to be broke down. No error message, but the host FSM just don't get the output variable.

Is it bug, or I misunderstand something?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #10 on: February 01, 2021, 12:47:05 PM »
Can you share the template here and I'll take a look.

s0963123

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #11 on: February 01, 2021, 07:26:01 PM »
Attached is the design of template.
The first state is only a next frame event.
And when you run this fsm, the debug log would get the correct output(which is 111), but the host FSM cannot get the output variable.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #12 on: February 02, 2021, 03:50:52 AM »
Thanks! This will be fixed in p3. The output values were off by one frame...

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #13 on: February 02, 2021, 01:09:31 PM »
1.9.1p3 is now in beta and should fix both of the bugs in this thread. Let me know if you get a chance to try it.

s0963123

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Run FSM: InvalidCastException: Specified cast is not valid.
« Reply #14 on: February 03, 2021, 09:05:05 PM »
Good to know.
Thanks so much.