playMaker

Author Topic: Setting default object type for FSMArrays in custom action  (Read 443 times)

kocosephia

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Setting default object type for FSMArrays in custom action
« on: April 11, 2018, 12:45:50 PM »
Hello! I have a hopefully simple question. I'm writing a custom action that wants to use an FSMarray of AudioClips as an input field.

I've tried using the array editor attribute on my public FSMArray fields:
Code: [Select]
[ArrayEditor(typeof(AudioClip), elementName: "Clip")]

But when I do this The values I play inside those arrays are cleared on play (serialization problem?)

I've also tried:
Code: [Select]
[ArrayEditor(VariableType.Object, elementName: "Clip")]

This works, and I can use audio clips fine in the action after doing some type checking, but there is a problem where I cannot select FSMArray variables in my FSM unless they are of type Object. I assume the problem is that the my FSMArray.ObjectType isn't set yet. But if that is the case, what is the correct way to do that in my action?

I've Tried
Code: [Select]
override Reset()
{
    [FSMArray] = new FSMArray();
    [FSMArray].ObjectType = typeof(AudioClip);
}

but this doesn't seem to work. Anyone have any suggestions for the correct way to do this?

Deek

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Setting default object type for FSMArrays in custom action
« Reply #1 on: April 12, 2018, 02:05:41 PM »
You might also need to define the object type with the attribute 'ObjectType', like so:
Code: [Select]
[ObjectType(typeof(AudioClip))]
[ArrayEditor(VariableType.Object, elementName: "Clip")]
public FsmArray myArray;

In the list of supported action attributes you can also see that the "fairly new" attribute 'ActionTarget' could be exactly what you're looking for (I haven't seen any use for it yet and never tried it myself, so I don't know for sure).

Sidenote: The Reset() function is only to specify default values for the action variables so that shouldn't be the place to define what type of object an array is supposed to contain.

kocosephia

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: Setting default object type for FSMArrays in custom action
« Reply #2 on: April 13, 2018, 08:47:48 AM »
Thank you Derek for you suggestions. Unfortunately neither ActionTarget or Objecttype worked in this case.

Where is the right place to set [FSMArray.ObjectType]? If I could answer that question, I could solve me problem.
« Last Edit: April 13, 2018, 09:39:08 AM by kocosephia »

g-reg

  • Playmaker Newbie
  • *
  • Posts: 1
    • View Profile
Re: Setting default object type for FSMArrays in custom action
« Reply #3 on: April 13, 2018, 06:45:08 PM »
I had this exact same problem today as well. I'm trying to make an FsmArray with a custom type, but when I enter play mode the array gets cleared unless I make an array variable in the FSM. I tried the same things as kocosephia, but it did not work.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3315
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Setting default object type for FSMArrays in custom action
« Reply #4 on: April 14, 2018, 06:13:02 AM »
Hi, I can confirm there's a bug with the arrays of custom types resetting on play  :-[

I'll get a fix into the next update.

The workaround, for now, is to make an array variable of the appropriate type and use that in the action parameter. You can use New Variable in the variable selection menu to quickly make the array variable (instead of multiple menus in the Variables tab). 

Sorry for the inconvenience!

kocosephia

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: Setting default object type for FSMArrays in custom action
« Reply #5 on: April 16, 2018, 07:58:14 AM »
Hi, I can confirm there's a bug with the arrays of custom types resetting on play  :-[

I'll get a fix into the next update.

The workaround, for now, is to make an array variable of the appropriate type and use that in the action parameter. You can use New Variable in the variable selection menu to quickly make the array variable (instead of multiple menus in the Variables tab). 

Sorry for the inconvenience!

Thanks so much for letting us know! Looking forward to the update. In the mean time, is it possible to use an FSMObject array and set the FSMArray.ObjectType property shortly after the array gets created? I notice that this works, but I'm not sure of the right place to do this. If I set the FSMArray.ObjectType in void Reset after a null check, this will work if I reset the action once after creating it, but won't create with that object type as the FSMArray is still null in the reset function.

So, is where is the best place to set FSMArray.ObjectType so that it gets set right after the instantiation of a new action?