Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: coxy17 on December 20, 2017, 06:26:15 AM
-
Hi
Im using a custom editor window and I want to be able to add a new variable when i press a GUI button using the API, but the only guide i found was accessing the fsm variable array and then adding the new value to it but I dont need to find it but just add.
I can see there is a FindFSMString and GetFSMString but is there something like a AddFSMString?
FsmVariables.GetFsmString("example")
all i want to do is essentially create a new variable and change its name and type. Like you would when you manually add a new variable in the FsmEditor.
Nick
-
bump
-
I don't think you can. Make an empty placeholder variable that will be used for transforming it to whatever you need.
-
Ok i have found the solution. I can get the variables used by the fsm using the following where 'myfsm' is the fsm you want to target.
myfsm.Fsm.Variables
then to get specific types of variables on a FSM I used.
myfsm.Fsm.Variables.StringVariables
myfsm.Fsm.Variables.IntVariables
myfsm.Fsm.Variables.BoolVariables
myfsm.Fsm.Variables.GameObjectVariables
After this I added the new variables to these arrays and saved over the old/current values.
//make a List from string var
List<FsmArray> list = myfsm.Fsm.Variables.StringVariables.ToList();
//add new value
list.Add("new string");
//save array of string variables back to the fsm
myfsm.Fsm.Variables.StringVariables = list.ToArray();
Then i changed the 'name' of the variable by referencing the index value of the FSM array.
myfsm.Fsm.Variables.StringVariables[0].Name = "new string var";
-
Nice solution, great. Do they stay saved upon exiting play mode?
-
no sure as im only updating values during edit mode using a EditorWindow custom script. Then update and save just fine, i'll let you know if i test during play mode.
-
Thanks, i'd really like to know.