Playmaker Forum

Bug Reporting => PlayMaker Bug Reporting => Topic started by: imtrobin on July 04, 2014, 07:44:46 AM

Title: Owner null in Awake
Post by: imtrobin 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?
Title: Re: Owner null in Awake
Post by: jeanfabre 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
Title: Re: Owner null in Awake
Post by: imtrobin 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> ();
   }

}
Title: Re: Owner null in Awake
Post by: Alex Chouls 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...
Title: Re: Owner null in Awake
Post by: jeanfabre 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
Title: Re: Owner null in Awake
Post by: Alex Chouls 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...
Title: Re: Owner null in Awake
Post by: jeanfabre 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
Title: Re: Owner null in Awake
Post by: imtrobin 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
Title: Re: Owner null in Awake
Post by: imtrobin on August 03, 2014, 02:43:47 AM
Do you need repro case?
Title: Re: Owner null in Awake
Post by: Alex Chouls on August 03, 2014, 10:37:31 AM
Sure. I haven't been able to repro here...
Title: Re: Owner null in Awake
Post by: imtrobin on August 04, 2014, 12:49:09 PM
PM you sample
Title: Re: Owner null in Awake
Post by: Alex Chouls 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?
Title: Re: Owner null in Awake
Post by: imtrobin 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.