playMaker

Author Topic: EditorWindow API update FSM values Issue [SOLVED]  (Read 904 times)

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
EditorWindow API update FSM values Issue [SOLVED]
« on: November 29, 2017, 08:10:14 AM »
Hi, Im using a custom EditorWindow to update variables in FSM's using the API and i can successfully update the FSM variables whilst in Editmode. But if i change scene or run the game, the values get reset back to the default? weird.

I can see that the values are changing in each FSM when i update it in my custom window and if i save the scene it still reverts back to the last known configuration. This was only a quick test and its all being called in ONGUI at the moment but wont stay this way.

here is a video of the issue.
https://drive.google.com/open?id=1YjT7as-C78WCv8wLYOy4IrxfB4OiHMFA

Code: [Select]
void OnGUI ()
{
PlayMakerFSM[] each = GameObject.Find("Main Camera").GetComponents<PlayMakerFSM>();

for (int s = 0; s < targetfsm.FsmStates.Length; ++s)
{
foreach(FsmStateAction action in targetfsm.FsmStates[s].Actions)
{
if (action.GetType() == typeof(HutongGames.PlayMaker.Actions.PlaymakerDataTables))
{
HutongGames.PlayMaker.Actions.PlaymakerDataTables pdt = (HutongGames.PlayMaker.Actions.PlaymakerDataTables)(action);

if (pdt.databaseName.Value == "Characters") //get db name from chosen
{
GUILayout.BeginHorizontal(EditorStyles.textArea); //pass in style

for (var i = 0; i < pdt.databaseColumnKeys.Length; i++)
{
//DATABASE TABLE KEYS
pdt.databaseColumnKeys[i] = EditorGUILayout.TextField("", pdt.databaseColumnKeys[i], EditorStyles.label, minwidth, expandwidth);
}
GUILayout.EndHorizontal();
}
}
}
}
}

« Last Edit: December 11, 2017, 01:52:41 AM by coxy17 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: EditorWindow API update FSM values Issue
« Reply #1 on: November 30, 2017, 11:36:15 PM »
Hi,

you need to watch for values being changed, raised a flag and after your editor code is run, if that flag is true you save the actions and flag the object dirty:

Code: [Select]

PlayMakerFSM _pfsm = GameObject.Find("Main Camera").GetComponent<PlayMakerFSM>();

bool dirty = false;

for (int s = 0; s < _pfsm.FsmStates.Length; ++s)
{
foreach(FsmStateAction action in _pfsm.FsmStates[s].Actions)
{
if (action.GetType() == typeof(HutongGames.PlayMaker.Actions.SetFloatValue))
{
HutongGames.PlayMaker.Actions.SetFloatValue pdt = (HutongGames.PlayMaker.Actions.SetFloatValue)(action);

float _newValue = EditorGUILayout.FloatField(new GUIContent("float Value"),pdt.floatValue.Value);

if (_newValue != pdt.floatValue.Value)
{
dirty = true;
pdt.floatValue = _newValue;
}
}
}
}

if (dirty)
{
_pfsm.Fsm.SaveActions();
EditorUtility.SetDirty(_pfsm.gameObject);
}



 Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: EditorWindow API update FSM values Issue
« Reply #2 on: December 01, 2017, 07:22:37 AM »
Thanks Jean

I have the code working now, although i have found an issue with updating FSMArray using the 'GetFsmArray'. I check to see if the value has changed but it doesnt work. The value reverts back to default after using '_pfsm.Fsm.SaveActions();' Why doesnt it work for this part of my code?

the 'databasekey' works, but the 'subArray' doesnt.

Code: [Select]
string databasekey = EditorGUILayout.TextField("", pdt.databaseColumnKeys[i], EditorStyles.label, minwidth, expandwidth);

//works ok
if (databasekey != pdt.databaseColumnKeys[i])
{
dirty = true;
        pdt.databaseColumnKeys[i] = databasekey;
}

//doesnt save
FsmArray subArray = _pfsm.FsmVariables.GetFsmArray(pdt.databaseColumnValues[i].variableName);

for (var x = 0; x < subArray.Length; x++)
{
switch (subArray.ElementType)
{
case VariableType.String:
string test = EditorGUILayout.TextField("", subArray.Values[x] as string, minwidth, expandwidth);
if (test != subArray.Values[x])
{
                                dirty = true;
subArray.Values[x] = test;
}
break;
}
}



coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: EditorWindow API update FSM values Issue
« Reply #3 on: December 01, 2017, 08:38:11 AM »
shall i use subArray.SaveChanges() ?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: EditorWindow API update FSM values Issue
« Reply #4 on: December 10, 2017, 11:12:53 PM »
Hi,

 yep, you likely need to save changes.

 Bye,

 Jean

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 199
    • View Profile
    • Haven Made
Re: EditorWindow API update FSM values Issue [SOLVED]
« Reply #5 on: December 11, 2017, 07:39:59 PM »
Woah Coxy17! Happy you figured out the issue, but I also want to say that tool looks SUPER handy! Any plans to commercialize it as a tool at some point?

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: EditorWindow API update FSM values Issue [SOLVED]
« Reply #6 on: December 12, 2017, 01:06:52 AM »
Hi craigz

Maybe, but the concept is just to speed up the workflow. More than likely ill just submit it to the playmaker ecosystem so others can benefit from it. Ill let you know when its done, so you can test it, if you want to?

Nick