Playmaker Forum
Bug Reporting => PlayMaker Bug Reporting => Topic started 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?
-
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
-
Yes, it is a custom action. I'm overriddering the Awake function like so
public class Test : FSMStateAction
{
TestComponent testComponent;
public override void Awake ()
{
// this is null
testComponent = Owner.GetComponent <TestComponent> ();
}
}
-
What version Playmaker/Unity/OS are you using?
I just ran some tests here and it was working fine...
-
Hi,
What would be the reason for using Awake to get to a component? Out of curiosity :)
Bye,
Jean
-
Awake is meant for expensive operations that you only want to do once.
So you could cache a component reference in Awake...
-
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:
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if(go != null)
{
_t = go.transform;
}
t will be null.
Bye,
Jean
-
Shucks, I'm not getting email notification on the replies.
Playmaker 1.7.7.2, Unity 4.3.3
-
Do you need repro case?
-
Sure. I haven't been able to repro here...
-
PM you sample
-
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?
-
I don't think I need Awake at edit time. I'm only linking nodes. It's runtime then I need the variables setup.