playMaker

Author Topic: Setting FSMArray through script error  (Read 2231 times)

jrDev

  • Junior Playmaker
  • **
  • Posts: 59
Setting FSMArray through script error
« on: March 08, 2016, 09:12:19 PM »
Hello,

I am new to scripting with playmaker and I want to set an array of audio clips to an fsmarray. Here is my code:
Code: [Select]
GameObject manager = GameObject.Find("QuestionBox_Manager");
PlayMakerFSM theFsm = manager.GetComponent<PlayMakerFSM>();

var theObjects = (UnityEngine.Object[])audioTriviaFiles.ToArray() as UnityEngine.Object[];

theFsm.FsmVariables.GetFsmArray("Voice Files").Values = theObjects;

This compiles, the problem arises when I hit play mode, Playmaker blanks out and throws this error:
Quote
InvalidCastException: Cannot cast from source type to destination type.
HutongGames.PlayMakerEditor.FsmVariable.EditFsmArrayValues (Boolean isAsset) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmVariable.cs:713)
HutongGames.PlayMakerEditor.FsmVariable.DoEditorGUI (UnityEngine.GUIContent label, Boolean isAsset) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmVariable.cs:627)
HutongGames.PlayMakerEditor.FsmVariablesEditor.DoVariableEditor () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmVariablesEditor.cs:815)
HutongGames.PlayMakerEditor.FsmVariablesEditor.OnGUI () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmVariablesEditor.cs:353)
HutongGames.PlayMakerEditor.VariableManager.OnGUI () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/VariableManager.cs:35)
HutongGames.PlayMakerEditor.InspectorPanel.OnGUI (Rect area) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/InspectorPanel.cs:188)
HutongGames.PlayMakerEditor.FsmEditor.OnGUI () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmEditor.cs:522)
HutongGames.PlayMakerEditor.FsmEditorWindow.DoGUI () (at Assets/PlayMaker/Editor/FsmEditorWindow.cs:110)
HutongGames.PlayMakerEditor.BaseEditorWindow.OnGUI () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/BaseEditorWindow.cs:72)
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-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
UnityEditor.EditorWindow:SendEvent(Event)
HutongGames.PlayMakerEditor.FsmEditor:Update() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmEditor.cs:778)
HutongGames.PlayMakerEditor.FsmEditorWindow:Update() (at Assets/PlayMaker/Editor/FsmEditorWindow.cs:351)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Any help would be appreciated.

Thanks,
jrDev

jrDev

  • Junior Playmaker
  • **
  • Posts: 59
Re: Setting FSMArray through script error
« Reply #1 on: March 08, 2016, 10:02:47 PM »
Hmm, I wonder if it's because I didn't change the type of the array to 'Object'. It was on float and ever since I changed it, the error is gone. If this was the solution, I wonder if you guys can show a more clear error than the one Unity throws?

Thanks,
jrDev