playMaker

Author Topic: Custom class variables not saving  (Read 4985 times)

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Custom class variables not saving
« on: May 23, 2013, 06:28:14 PM »
I'm trying to create an array of FSM variable groups. This way for example I could have an action that waits for 5 keys to be pressed and trigger the appropriate event based off which key was pressed all done in 1 action instead of 5 actions. I like the concept of reducing overhead by reducing the need for multiple same actions. For normal C# scripting you'd just use a class as a variable that has public variables in it and this works for normal scripting, but it does not for PlayMaker. By I mean it does not I mean the variables do not save, but display fine.

Code: [Select]
    [System.Serializable]
    public class CustomPlayMakerActionList {
        public FsmString var1;
        public FsmString var2;
        public FsmString var3;

    }

    [ActionCategory("Testing")]
    public class CustomPlayMakerAction : FsmStateAction {
        public CustomPlayMakerActionList[] test;

Above is an example of this usage. The display works fine, but var1-3 will not save after pressing play.

Do you have any ideas or suggestions on how to get this working or perhaps a better way to get what I'm wanting? I posted this below on Unity forums, but believe would be more helpful to the community to discuss here.

http://forum.unity3d.com/threads/72349-Playmaker-a-new-visual-scripting-tool/page59?p=1253294&viewfull=1#post1253294

I really hope this can be done and if not can it be implemented please and if it can is there anything I can do to help? I am an avid PlayMaker user and have currently 272 custom PlayMaker actions and am always looking to improve upon them. I do play to release my actions after my game is completed and released as well; the range from Assets being integrated into PlayMaker to custom ones for very cool behavior (2.5D camera scrolling, 2.5D physics based controller, etc..).

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Custom class variables not saving
« Reply #1 on: May 23, 2013, 10:43:14 PM »
Hi,

 FsmVar exists already ( I replied on your forum thread).

 and custom class are working for me quite well, I did some more tests today

I don't need to use [System.Serializable] it works fine without. And I also can create custom class that features PLaymaker fsm variable to show the usual ui within custom action. VERY COOL! the downside is that it shows up in the action list, but that's not too bad, you can categorize them into a "INTERNAL" category so that it's clearer maybe.


I have attached a sample showing proper use of custom class, and actions using custom class, and all serializization is fine as far as I can see.

 if you can't make that scene working, let me know.

bye,

 Jean

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Custom class variables not saving
« Reply #2 on: May 24, 2013, 05:21:46 AM »
I have exactly the same usage as CustomClassActionTest, but with 1 difference; I'm using an array. When I don't use an array it works fine, but when I do use an array it won't save the variables. In your own example make the below change and it won't work.

FROM:
Code: [Select]
public CustomClassTestRaw rawClass;
TO:
Code: [Select]
public CustomClassTestRaw[] rawClass;

As soon as you press play after setting the index and adding strings to content it'll blank the values.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3202
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Custom class variables not saving
« Reply #3 on: May 24, 2013, 09:15:33 AM »
Saving arrays of a custom class is currently not supported. Will try to get that working asap...

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Custom class variables not saving
« Reply #4 on: May 24, 2013, 01:36:45 PM »
Saving arrays of a custom class is currently not supported. Will try to get that working asap...
Awesome, be great to have it working in next release. I'll be happy to test any implementations of it as well to be sure is working ok before release.

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Custom class variables not saving
« Reply #5 on: May 25, 2013, 02:07:36 PM »
It looks like CompoundArray will also work for what I am trying to do, but it only supports 2 values; I need more than that. Can I perhaps write my own script to extend this maybe?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3202
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Custom class variables not saving
« Reply #6 on: May 25, 2013, 02:22:55 PM »
You could write a CustomActionEditor ;)

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Custom class variables not saving
« Reply #7 on: May 25, 2013, 03:05:24 PM »
Well I wrote CompoundArrayExtendedAttribute as follows to support up to 6 attributes, but it doesn't group together like the CompoundArrayAttribute usage does.

Code: [Select]
using System;

namespace HutongGames.PlayMaker {
[AttributeUsage(AttributeTargets.Field)]
public sealed class CompoundArrayExtendedAttribute : Attribute {
private readonly string name;
private readonly string firstArrayName;
private readonly string secondArrayName;
private readonly string thirdArrayName;
private readonly string forthArrayName;
private readonly string fifthArrayName;
private readonly string sixthArrayName;

public string Name {
get {
return this.name;
}
}

public string FirstArrayName {
get {
return this.firstArrayName;
}
}

public string SecondArrayName {
get {
return this.secondArrayName;
}
}

public string ThirdArrayName {
get {
return this.thirdArrayName;
}
}

public string ForthArrayName {
get {
return this.forthArrayName;
}
}

public string FifthArrayName {
get {
return this.fifthArrayName;
}
}

public string SixthArrayName {
get {
return this.sixthArrayName;
}
}

public CompoundArrayExtendedAttribute( string name, string firstArrayName, string secondArrayName ) {
this.name = name;
this.firstArrayName = firstArrayName;
this.secondArrayName = secondArrayName;
}

public CompoundArrayExtendedAttribute( string name, string firstArrayName, string secondArrayName, string thirdArrayName ) {
this.name = name;
this.firstArrayName = firstArrayName;
this.secondArrayName = secondArrayName;
this.thirdArrayName = thirdArrayName;
}

public CompoundArrayExtendedAttribute( string name, string firstArrayName, string secondArrayName, string thirdArrayName, string forthArrayName ) {
this.name = name;
this.firstArrayName = firstArrayName;
this.secondArrayName = secondArrayName;
this.thirdArrayName = thirdArrayName;
this.forthArrayName = forthArrayName;
}

public CompoundArrayExtendedAttribute( string name, string firstArrayName, string secondArrayName, string thirdArrayName, string forthArrayName, string fifthArrayName ) {
this.name = name;
this.firstArrayName = firstArrayName;
this.secondArrayName = secondArrayName;
this.thirdArrayName = thirdArrayName;
this.forthArrayName = forthArrayName;
this.fifthArrayName = fifthArrayName;
}

public CompoundArrayExtendedAttribute( string name, string firstArrayName, string secondArrayName, string thirdArrayName, string forthArrayName, string fifthArrayName, string sixthArrayName ) {
this.name = name;
this.firstArrayName = firstArrayName;
this.secondArrayName = secondArrayName;
this.thirdArrayName = thirdArrayName;
this.forthArrayName = forthArrayName;
this.fifthArrayName = fifthArrayName;
this.sixthArrayName = sixthArrayName;
}
}
}

Quote
You could write a CustomActionEditor
I understand that, but how; lol. I can do lots of things, but I need a tangible example of how to accomplish this. I assume after doing the above I need just a simple GUI script to handle the display and I'll be good to go. As I understand the custom action editor is for a specific action, this is a bit different and don't know if it'd work as it's not an action, but an attribute.

On a side note is there plans to release source? Would be happy to pay a source license fee (maybe 3x normal cost?).

Edit: Think I found what I'm missing. Decompiled the editor DLL and looks like I need to add to ActionEditor a GetCompoundArray and EditCompoundArray functions and variables (appears to be compoundArrayList, compoundArrayParent, and compoundArrayChild) as well as adjustments to EditField for it to be handled. Is it possible to do this in a custom action editor script (I assume so based off the name CustomActionEditor, lol). Be happy to share the scripts as well once/if I can get this working.
« Last Edit: May 25, 2013, 03:28:21 PM by Krileon »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Custom class variables not saving
« Reply #8 on: May 26, 2013, 11:00:34 PM »
Hi,

 ok, I am currently working on a custom action editor to give you an example, but I am really confused as to what is your goal here actually. Could you explained a bit more what is the use case for such action? Thanks.

I think that you are trying to do too much within one action. Why ArrayMaker is not an option in your case? it looks to me that this would be perfect for what it seems you are trying to achieve.

Actions "should" not store data, I think this is a wrong approach, and if you need to list and reference that much data in so many different lists, then really, it's either that you need a database, or something simpler like ArrayMaker.

Bye,

 Jean

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Custom class variables not saving
« Reply #9 on: May 27, 2013, 08:47:17 AM »
Quote
ok, I am currently working on a custom action editor to give you an example, but I am really confused as to what is your goal here actually. Could you explained a bit more what is the use case for such action? Thanks.
It's just array grouping of variables. Example as follows.

Count: 3
-----------------------
Key:
Primary Input:
Secondary Input:
-----------------------
Key:
Primary Input:
Secondary Input:
-----------------------
Key:
Primary Input:
Secondary Input:

This is already implemented with custom classes, but the values don't save so that's not an option. The alternative was using a custom variable, but there's no GUI handling for it so that doesn't work and the existing only supports 2 variables. Ideally custom class variable with array usage is what I want, but as Alex said above it's not working atm.

Quote
I think that you are trying to do too much within one action. Why ArrayMaker is not an option in your case? it looks to me that this would be perfect for what it seems you are trying to achieve.
I don't want to use ArrayMaker. I want to use my own code. ArrayMaker is bloated for what I need and want. PlayMaker can already handle arrays perfectly fine and was extremely simple to implement with Lists and string serialization so ArrayMaker doesn't serve me any purpose.

Quote
Actions "should" not store data, I think this is a wrong approach, and if you need to list and reference that much data in so many different lists, then really, it's either that you need a database, or something simpler like ArrayMaker.
It's not storing anything so I don't know what you're referring to. ArrayMaker isn't simple, it bloats your install with actions you don't even need. String serialization and array handling is already in PlayMaker and handling arrays with a single variable or even 2 variables is extremely simple. I want to handle array variable grouping with unlimited potential, which just requires custom class variables when being used as an array to be able to not lose the variable. I don't know how much more to explain this, see my previous posts as I've already provided examples and exactly how to duplicate the problem (example in first post).

The purpose of all this is to avoid redundantly having multiple actions for the same action. For example I have cInput actions I wrote and I want to bind the primary and secondary keys to a key name at start up (this establishes the defaults) and it works perfectly fine, but if I have to set the defaults for 10 keys then I need 10 actions which is stupid; this should be 1 action with array looping (the exact same usage you see when using PlayerPrefs, but with more than 2 variables). There are a ton of cases where array handling like this is most ideal to avoid firing 5+ actions in a row to do the same action with different variables and improves performance.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Custom class variables not saving
« Reply #10 on: May 27, 2013, 11:00:07 PM »
Hi,

 Ok, fair enough. Still working on the custom editor, allow some time to get there.

 Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Custom class variables not saving
« Reply #11 on: May 28, 2013, 01:36:39 AM »
Hi,

 Ok, please find a package with some play with a custom editor and arrays of variables within a custom class.

Basically, what I did is the following, I am mapping Unity Inputs with custom keys, so you can define a custom key for a given Unity Input, Not very useful, but shows the process.

also, you'll find that when playing, the action displays the value of the input live, and if the input is not found, it will output the error. Some goodies of writing custom editors :)

 I hope this will set you on the rigth track, basically, it's all there for you to expand and fit this to your needs, it shows how to declare the custom class, and it shows how to create custom editor GUI to work with it.

Also, you'll find some quick editing features, such as adding new items, combining two arrays in the custom class into one compound array to the end user, and the ability to delete a particular item ( not just the last one, like in Unity, which is lame... I need to update ArrayMaker to do this too :) )

Warning. You can't use Fsmxxx in arrays in this case, cause you don't have access to the ui widget of an fsm type when the property is not public, I have requested this ability on the beta, it would be great to be able to simply ask the action editor to display the widget on its own, and we then link it to whatever. This will allow us to create compounds arrays with fsm vars, that will be ultra powerful indeed!


bye,

 Jean

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Custom class variables not saving
« Reply #12 on: May 28, 2013, 06:45:55 AM »
Thank you for the efforts, but is still not what I am after. I am wanting array variable grouping. I'm not sure how much more to explain. Simply put you have 3 variables, all 3 variables are arrays, but the 3 variables are grouped together with the same indexes. This is either done with a custom variable component (which is available, but only works with 2 variables) or done with a custom class variable (which is also available, but doesn't work with arrays).

The "Custom Class Test" is no different then using [] with an FSM variable (which you can do and works fine) and "Custom Class Action Test" just has a button called "Input" that throws errors when pressed. However, even if this worked you couldn't use FsmVariables in it and would defeat its purpose as I need to use FsmVariables.

In conclusion will need to wait for Alex to implement array handling of custom class variables.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Custom class variables not saving
« Reply #13 on: May 28, 2013, 10:03:37 PM »
Hi,

 ok, no worries, it was a good exercise anyway.

I am not sure tho about what you experience with the package I sent, There is no "Input" button, there is an "Add Input" button and that works: it creates a new compound entry of key and input, and it doesn't fire error. If it does, can you tell me what error it throws, because all my tests did not fire any errors? you might have not imported the package properly for some reason or you may be doing something that I haven't planned, in which case it would be good to address it.

bye,

 Jean

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Custom class variables not saving
« Reply #14 on: May 29, 2013, 06:12:00 AM »
Hi,

 ok, no worries, it was a good exercise anyway.

I am not sure tho about what you experience with the package I sent, There is no "Input" button, there is an "Add Input" button and that works: it creates a new compound entry of key and input, and it doesn't fire error. If it does, can you tell me what error it throws, because all my tests did not fire any errors? you might have not imported the package properly for some reason or you may be doing something that I haven't planned, in which case it would be good to address it.

bye,

 Jean
I just imported it into a clean project that only had latest PlayMaker in it. Then added the 2 custom actions to an empty gameobject. I then pressed the button and does nothing except error. Perhaps you missed some scripts to include in the package? Anyway, I deleted the project so don't have the error anymore, sorry.