playMaker

Author Topic: [SOLVED] GetProperty won't give option to store property  (Read 4124 times)

sgoon

  • Playmaker Newbie
  • *
  • Posts: 8
[SOLVED] GetProperty won't give option to store property
« on: March 18, 2012, 12:24:21 AM »
Hi everyone,

I am a little stumped. I have a custom Entity component (monobehaviour) and am using GetComponent in my FSM to store that component in a variable. That part is working fine. However, I'm then trying to access a public bool on that component called isAlive from that stored object.

When I add the GetProperty action to my state, it allows me to select that variable for the object, and it populates the list of properties correctly, but if I select any of the Entity class properties, the store variable line disappears from the action inspector. However, if I go down to the inherited subsection, and chose one of the inherited properties (from monobehaviour) suddenly I can store them again.

Am I misunderstanding how GetProperty is supposed to work? I could have sworn you could use it to store standard, public data-types from custom components, but maybe I'm crazy. Thanks for any help you can give.

-Sean

UPDATE:

This only happens when I'm accessing my Entity class as an FSMObject variable. If I just drag an entity component onto the action, it works fine. If I try to use the stored object, the Type updates correctly (and says "Entity") but I lose the store ability.
« Last Edit: May 20, 2012, 02:42:55 AM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: GetProperty won't give option to store property
« Reply #1 on: March 18, 2012, 01:03:25 AM »
Sounds like a bug... Can you send me your Entity component?

sannyasi

  • Playmaker Newbie
  • *
  • Posts: 8
Re: GetProperty won't give option to store property
« Reply #2 on: May 13, 2012, 06:01:41 AM »
Does this only work with Properties as the name implies or should it work with any standard field type???

If I make a monoBehaviour with a single float field, I get the same error.
But if I switch it to a float get set property the store variable option comes back.

Windows7 pro x64
Unity 3.5.1f2
Playmaker 1.3.3 (17412)

ddfire

  • Playmaker Newbie
  • *
  • Posts: 2
Re: GetProperty won't give option to store property
« Reply #3 on: May 14, 2012, 02:50:36 PM »
Quote
But if I switch it to a float get set property the store variable option comes back.
may you post an example?
because i have this (tried with the variable public, private, protected and nothing):

   Transform parent;
   public Transform getParent(){
      return Next;
   }
   
   public void setParent(Transform lNext){
      Next = lNext;
   }

Thanks

sannyasi

  • Playmaker Newbie
  • *
  • Posts: 8
Re: GetProperty won't give option to store property
« Reply #4 on: May 17, 2012, 09:33:53 PM »
You need to make a Get Set style property... not a method (notice the parenthesis "()" on the method ):

Code: [Select]
// Method that returns a type of Transform
public Transform setParent()
{
}

A property looks like this

Code: [Select]
public TYPE NAME
{
    get {return VARIABLE;}
    set {VARIABLE = value;}
}



Sounds like your trying to access the transform component of your gameObject.
General rule of thumb is to make a private field that is controlled through a public property, so
First make a private field ( usually the same name as the property but with an "_" before the name)


Code: [Select]
private Transform _myTransform;
Then the property:

Code: [Select]
public Transform myTransform
{
    get { return _myTransform;}
    set { _myTransform = value;}
}


Notice In my example I've changed your name from "transform" to "myTransform",
the reason being that transform is a built in property of Unity that exists on all gameObjects already.
If you specify yours with the same name you will override the builtin one.

Properties are a great way to manage your class's variables that allow a lot more control than simply setting a value,
I would strongly recommend reading up on them, espesially since this is how to get values in and out of playmaker.

Let me know if that all makes sense.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: GetProperty won't give option to store property
« Reply #5 on: May 18, 2012, 02:14:40 PM »
Have you tried this in 1.4.0? There were some fixes for FsmObjects and Get/Set Property...

sannyasi

  • Playmaker Newbie
  • *
  • Posts: 8
Re: GetProperty won't give option to store property
« Reply #6 on: May 18, 2012, 08:29:17 PM »
Just updated to 1.4 and the get property now works with fields, so ddfire you can now access your fields directly rather than going through a property.

Thanks for the update.