playMaker

Author Topic: [solved] FsmStateAction.Owner is null at "Awake"?  (Read 7227 times)

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
[solved] FsmStateAction.Owner is null at "Awake"?
« on: November 13, 2013, 09:02:22 AM »
Hi,

is it normal/correct that the FsmStateAction.Owner is not yet set inside Awake()/ErrorCheck()? I need to-do some init/error handling based on the Owner, but i only get a valid owner at "OnEnter()", which i don't understand?

The Owner should be available from the moment i attach a Fsm Component to a Gameobject, so why is it null inside "Awake/ErrorCheck", is there some extra logic for the FsmStateAction missing?

Maybe my assumption that by default a FsmStateAction has the same Owner as the Fsm is false?

thx Andy
« Last Edit: November 26, 2013, 09:21:15 AM by Andy22 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: FsmStateAction.Owner is null at "Awake()/ErrorCheck()"?
« Reply #1 on: November 14, 2013, 12:53:18 AM »
Hi,

 It could be by design actually, Awake is a very early call, so it may be a Unity Restriction.

Can you file a bug report on this? it's a very important point to get defined.

Can you give the context of what you want to achieve? because check can happen onEnter, because you do anything, so I am not sure I can find a use case to check for the owner in the awake and not just the first time its needed and that's all.

bye,

 Jean

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: FsmStateAction.Owner is null at "Awake()/ErrorCheck()"?
« Reply #2 on: November 14, 2013, 04:20:27 AM »
I'm talking about the "Awake/ErrorCheck" calls declared inside FsmStateAction. Those are not directly related to Unity's native Awake() call, since FsmStateAction is not a MonoBehaviour, so they just try to emulate similar behavior.

In Unity i expect that inside Awake/Start all base members are already properly setup/init. So u can use/check transforms/parents/owner/root/gameobject/camera and so on. I would expect the same for a FsmStateAction, if it has a "Awake" wrapper and a "Owner" property.

The case for Awake is the same than any Unity Awake, do some ctor setup and error checking, before the Action is actually used. The only difference seemed that we tried to use the FsmStateAction.Owner, instead of some public GameObjectLink field.

bye Andy

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: FsmStateAction.Owner is null at "Awake()/ErrorCheck()"?
« Reply #3 on: November 14, 2013, 05:53:31 AM »
Hi,

 Yes, that's what I meant too. These monobehavior restrictions are still quite valid when a fsm starts, at some point the first action of the first state will have its awake method call, and that could be still too soon.

Do you this problem when objects and fsm are already running and way past their starting state stacks of actions?

 Can you give a context still? cause I am still quite sure it can be all done without the need to do it in awake.

bye,

 Jean

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: FsmStateAction.Owner is null at "Awake()/ErrorCheck()"?
« Reply #4 on: November 14, 2013, 06:31:09 AM »
Hi,

Can you give a context still? cause I am still quite sure it can be all done without the need to do it in awake.

bye,

Jean

Like noted i found workarounds already, the point is not if it can be done outside of Awake(). Awake is the only ctor call we can use, so all init/ctor should go into it and not into some other call. I just found it "strange" that the Action's Owner is not yet set, which i would expect at this point.

Its by no means a big issue, just tried to point it out, since this could have been a bug. If its by design, maybe just add a comment to the StateAction.Owner property, that it is not valid outside of Enter/Update.

bye Andy

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: FsmStateAction.Owner is null at "Awake()/ErrorCheck()"?
« Reply #5 on: November 14, 2013, 06:36:03 AM »
Hi,

design/bug, that's what I am unsure, so it's best if you can fill out a bug to pass run a check on this.

I would still be curious about what makes you think that you must use the awake call of the action to perform tasks. You may have a very good set of points for actions to evolve in the right directions.


bye,

 Jean

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: FsmStateAction.Owner is null at "Awake()/ErrorCheck()"?
« Reply #6 on: November 14, 2013, 06:44:32 AM »
I would still be curious about what makes you think that you must use the awake call of the action to perform tasks.

What do u mean?

Where else u can put ctor/init/caching/error check logic into that only runs once per game-start?

bye Andy

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: FsmStateAction.Owner is null at "Awake()"?
« Reply #7 on: November 14, 2013, 07:20:51 AM »
Fast correction/update.

The "Action.Owner" is actually set/available inside ErrorCheck, but not Awake().

I also found that there is also a actual action.Init() call, that sets the owner correctly.

So i should just move my Awake logic, just inside Init. There is unfortunately no documentation on Awake/Init on the custom actions page https://hutonggames.fogbugz.com/default.asp?W350.

Also awake is called before Init, which explains why the owner is not yet set.
So this seems all fine, since if a explicit Init call exists, its not unexpected that inside awake the object is indeed "unInit" if it's called before Init :p
I just assumed Unity logic after i found awake, since Unity has no Init calls and u do all ctor stuff inside awake.


Sorry for the trouble.


bye Andy

« Last Edit: November 14, 2013, 07:45:52 AM by Andy22 »

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: FsmStateAction.Owner is null at "Awake"?
« Reply #8 on: November 25, 2013, 07:42:35 AM »
Hi,

i have to come back to this, since after creating our prefabs it became visible that Init() is acting more like a "UIRefresh" than a actual action.ctor/init. This means Init is called on every internal UI Refresh/handler and calls like "Fsm.GetOwnerDefaultTarget" do not work correctly if its a prefab, since it is called in the context of the editor and not the game.

So Init() cant be used as ctor or awake replacement, so keep this in mind if u want to use Init. So using awake and be aware of the owner problem, is what works atm.

bye Andy
« Last Edit: November 25, 2013, 07:46:02 AM by Andy22 »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: FsmStateAction.Owner is null at "Awake"?
« Reply #9 on: November 25, 2013, 08:11:18 AM »
Owner should be correct in Awake in the latest release (1.7.6)

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: FsmStateAction.Owner is null at "Awake"?
« Reply #10 on: November 26, 2013, 09:20:58 AM »
Owner should be correct in Awake in the latest release (1.7.6)

Thx, can confirm this for 1.7.6.