Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Aaddiction on April 27, 2015, 05:52:57 PM
-
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:
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.
-
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
-
Hi. I could not get this to work. Does anyone know a way? Thanks.
-
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
-
I have script1 like this
public class Script1 : MonoBehaviour
{
public int Vone;
[System.Serializable]
public script2[] otherVs;
}
and script2 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.
-
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:
(http://i.imgur.com/JWbocOU.png)
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;
}
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
-
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.
-
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