playMaker

Author Topic: Access [System.Serializable] with Set Proprety action. [SOLVED]  (Read 4127 times)

Aaddiction

  • Full Member
  • ***
  • Posts: 166
Hi,

Get/Set Property works well for accessing public variables within a class. But in my case a have a class withing the class with [System.Serializable].

So I have this:

Code: [Select]
public class Script1 : MonoBehaviour
{

}
[System.Serializable]
public class Script2
{
public float to access = 1;
}


How can I access "public float to access" with Playmaker, cause in this case set Property does not work.

Thank you.
« Last Edit: March 24, 2016, 01:53:08 PM by Alex Chouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Access [System.Serializable] with Set Proprety action.
« Reply #1 on: April 28, 2015, 12:57:40 AM »
Hi,

 you need a Component context for this class to exists, then you can access it.

 Script2 should be a public property of Script1, and then get/set property will expose "Float to access" via Script 1.

 Bye,

 Jean

jarden

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Access [System.Serializable] with Set Proprety action.
« Reply #2 on: March 22, 2016, 05:50:34 PM »
Hi. I could not get this to work. Does anyone know a way? Thanks.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Access [System.Serializable] with Set Proprety action.
« Reply #3 on: March 23, 2016, 03:12:46 AM »
Hi,

Can you paste the exact component and serialized class you are testing this with, because in your code sample, you don't show how you are using the serialized class inside the component. I'll try to repro then locally. In short Script2 is not used in Script 1... so it's not accessible yet to script 1, so set property on script1 will not show any option.

Bye,

 Jean

jarden

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Access [System.Serializable] with Set Proprety action.
« Reply #4 on: March 23, 2016, 05:41:52 PM »
I have script1 like this
Code: [Select]
public class Script1 : MonoBehaviour
{
     public int Vone;
     [System.Serializable]
     public script2[] otherVs;
}
and script2
Code: [Select]
public class Script2 {
     public int V1
     public Vector3 V2
}

The problem is I can't use "get property" with playmaker to get V1 or V2 if the script is not on an object. I just want to know if theres a way around this without auto adding script2 when you add script1 to something? Thanks.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Access [System.Serializable] with Set Proprety action.
« Reply #5 on: March 24, 2016, 03:28:06 AM »
Hi,

In your post, Script2 is not a valid script. So I am not sure with what you are testing for real.

In all cases, you need to have Script2 flagged as serializable, not otherVs.

Also, built in arrays are not supported for reflection with "Set Property" and "Get Property", so you 'll need for this a dedicated custom action, let me know if you need a working sample or you are fine that option.

so I made a working test to make sure it's all fine:



Code: [Select]
using UnityEngine;
using System.Collections;

public class Script1 : MonoBehaviour {

public int MyInt;
public Script2 MyScript2 = new Script2 (); // fine

// This won't be accessible via Get Property Set Property. you'll need a dedicated Custom Action too access the content of MyScript2List;
//public Script2[] MyScript2List;
}

Code: [Select]
using System;
using UnityEngine;

[Serializable]
public class Script2
{
public int MyInt;
public Vector3 MyVector3;
}

 Let me know fit that works better on your end.

Bye,

 Jean

jarden

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Access [System.Serializable] with Set Proprety action.
« Reply #6 on: March 24, 2016, 05:50:02 AM »
Thanks for the help. You answered my question with the line:

public Script2 MyScript2 = new Script2 (); // fine

I was only using [System.Serializable] to get the added inspector functionality of arrays of settings within arrays of settings, but the line above does it and works with playmaker.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Access [System.Serializable] with Set Proprety action.
« Reply #7 on: March 24, 2016, 06:57:58 AM »
Hi,

 Yep, I have been there :) it's always tricky to understand when things are created by default, and when they just are null until you set them up with a pointer reference.

 Basically/usually with complex behaviours comes a custom Inspector, and depending on your data, you may want to create Script2 within the Inspector code for example, so in the future, if this is growing and such declaration isn't suitable, remember you have plenty of options within the custom inspector script itself.

Bye,

 Jean