playMaker

Author Topic: Owner null in Awake  (Read 5418 times)

imtrobin

  • Playmaker Newbie
  • *
  • Posts: 28
Owner null in Awake
« on: July 04, 2014, 07:44:46 AM »
Hi,

I'm using Awake to get component on the Owner. From what I understand, this is what it is meant for. At runtime it works fine, but at design time, the Owner returns null. Is that intended?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Owner null in Awake
« Reply #1 on: July 21, 2014, 08:20:26 AM »
Hi,

 PlayMaker only runs when you press "play" in the editor, I am not sure where you make the distinctation in your explanation. Can you precise?

There is only a "START" in FSM, not an "AWAKE", even tho under the hood it's a mix of both.

You are writing custom actions right?

Bye,

 Jean

imtrobin

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Owner null in Awake
« Reply #2 on: July 22, 2014, 11:27:24 AM »
Yes, it is a custom action. I'm overriddering the Awake function like so

Code: [Select]
public class Test : FSMStateAction
{
    TestComponent testComponent;

   public override void Awake ()
   {
     // this is null
      testComponent = Owner.GetComponent <TestComponent> ();
   }

}

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Owner null in Awake
« Reply #3 on: July 22, 2014, 11:59:27 AM »
What version Playmaker/Unity/OS are you using?
I just ran some tests here and it was working fine...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Owner null in Awake
« Reply #4 on: July 22, 2014, 02:39:58 PM »
Hi,

 What would be the reason for using Awake to get to a component? Out of curiosity :)

 Bye,

 Jean

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Owner null in Awake
« Reply #5 on: July 22, 2014, 05:15:27 PM »
Awake is meant for expensive operations that you only want to do once.
So you could cache a component reference in Awake...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Owner null in Awake
« Reply #6 on: July 25, 2014, 02:10:47 AM »
Hi,

 funny, I just came to the same conclusion as I created a new custom action... Indeed the following doesn't work on Awake call:

Code: [Select]
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if(go != null)
{
_t = go.transform;
}

t will be null.

Bye,

 Jean

imtrobin

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Owner null in Awake
« Reply #7 on: July 25, 2014, 12:23:19 PM »
Shucks, I'm not getting email notification on the replies.

Playmaker 1.7.7.2, Unity 4.3.3

imtrobin

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Owner null in Awake
« Reply #8 on: August 03, 2014, 02:43:47 AM »
Do you need repro case?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Owner null in Awake
« Reply #9 on: August 03, 2014, 10:37:31 AM »
Sure. I haven't been able to repro here...

imtrobin

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Owner null in Awake
« Reply #10 on: August 04, 2014, 12:49:09 PM »
PM you sample

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Owner null in Awake
« Reply #11 on: August 05, 2014, 09:07:06 AM »
Thanks for the sample.

So it's an interesting issue is with templates. The null ref exception happens when you click to edit the template.

Templates do not have an Owner at edit time. Since they can be owned by many FSMs... At runtime the template is instantiated, so each instance has an owner.

There are a couple of options:
- Not call Awake at edit time. Are you relying on Awake being called at edit time?
- Not call Awake on templates. Not sure I like this inconsistency...

Do you have a preference or other ideas?

imtrobin

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Owner null in Awake
« Reply #12 on: August 05, 2014, 04:27:28 PM »
I don't think I need Awake at edit time. I'm only linking nodes. It's runtime then I need the variables setup.