playMaker

Author Topic: "IEnumerator Start()" equivalence in action  (Read 7127 times)

Jake

  • Junior Playmaker
  • **
  • Posts: 61
    • Fluffy Underware
"IEnumerator Start()" equivalence in action
« on: May 06, 2013, 02:09:55 PM »
Hi,

I've got an action that let's a gameobject return one of it child gameobject in OnEnter(). The problem is that with Unity you can't be sure that the parent gameobject's Start() has already run, so sometimes the FSM returns nothing. So the parent object has a IsInitialized property that I usually check in Start:

Code: [Select]
IEnumerator Start()
{
   while (!myObject.IsInitialized())
     yield return null;
  // myObject is initialized now, access it's childs:
  myObject.GetChild(1);
}

My question: How should I design my action to reflect this?

Thanks in advance
Jake

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "IEnumerator Start()" equivalence in action
« Reply #1 on: May 07, 2013, 03:42:15 AM »
Hi,

 Use events. Fire an event when your object is initialized, that's the best way to go about it.


so you have one fsm on MyObject, it's responsible for checking that it is initialized ( what ever that means in your game), fire a custom event like " OBJECT READY" for example.

in a second fsm ( if you want, you can perfectly have this working in one fsm as well). listen to that "OBJECT READY" event as a global transition.

 does that make sense?

bye,

 Jean


bye,

 Jean

Jake

  • Junior Playmaker
  • **
  • Posts: 61
    • Fluffy Underware
Re: "IEnumerator Start()" equivalence in action
« Reply #2 on: May 07, 2013, 04:27:26 AM »
I'll try this, though I would prefer a way to yield inside an action.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "IEnumerator Start()" equivalence in action
« Reply #3 on: May 07, 2013, 06:28:55 AM »
Hi,

 That's the beauty of PlayMaker, "yield" IS playmaker Fsm system!

Code: [Select]
Do-this

Yield Some-Condition

Do-that

translates in PlayMaker as follow:

you have one state that you name "Do.this"

on that "do.This" state, add a transition that you would call "SOME CONDITION TRUE" that links to a state called "Do-That"

 Does that make sense? This is the most important design pattern of PlayMaker.


as far as I am concerned, I really can not script yields statement anymore in c#... I always use a fsm for this, and if the project doesn't have playmaker yet, that means it needs it :) that's a key aspect to look for when you don't know for sure if playmaker is needed in your project. keep the hardcode stuff as custom actions or external scripts you call, but to handling the flow of your feature, PlayMaker is king.

when you use Yield statement in scripts, you can't debug properly, you get quickly lost as soon as the flow has a bug, and passed 2 or 3 yields dependencies... you find yourself going back and forth between script to try and remember the actual flow...

 With playmaker, it's all visual!! so it's clearly in front of you, AND you can see the flow in bright green as it plays... something invaluable! coupled with the debugFlow that you can simply pause your game and go back in time to see where and how the flow of events proceeded is a killer!


Could you explain what exactly you are willing to achieve, I can certainly help you model the fsm, and then you'll see if that's suitable for you? you may have a special need indeed.

 Bye,

 Jean



Jake

  • Junior Playmaker
  • **
  • Posts: 61
    • Fluffy Underware
Re: "IEnumerator Start()" equivalence in action
« Reply #4 on: May 07, 2013, 08:53:10 AM »
Thanks for the detailed explanation, you're right. Although I want to "hide" the needed extra state from the end user:

The problem arose with the playMaker package for Curvy. In particular, CurvyGetControlPoint returns a control point as a gameObject. It does so by calling the parent spline's API. However, due to the nature of Unity you can't be sure that all needed gameObjects have been intialized properly (changing the script execution order is a mess and can't be coded, so no no), hence the IsInitialized property of the parent, that usally is a solid solution when not using pM.

Jake


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "IEnumerator Start()" equivalence in action
« Reply #5 on: May 08, 2013, 12:49:56 AM »
Hi,

 Yes, I see what you mean now. For this kind of start up mess, I most of the time end up writing a small framework.

 By end user you mean fellow developers right?

 Have you considered using sub fsm? you could inside a very simple sub fsm action have a fsm that wait for init calls, your fsm will stay clean because all the routine is encapsulated within a sub fsm.

bye,

 Jean

Jake

  • Junior Playmaker
  • **
  • Posts: 61
    • Fluffy Underware
Re: "IEnumerator Start()" equivalence in action
« Reply #6 on: May 08, 2013, 03:19:14 AM »
I'm not quite sure how to set this up. Could you give me a small example? I can send you the Curvy package if needed.

Thanks for your help

Jake

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "IEnumerator Start()" equivalence in action
« Reply #7 on: May 09, 2013, 02:31:54 AM »
Hi,

 I don't own curvy unfortunatly, and it's not allowed to shared packages from the asset store. What happens generally, is that if you want me to support an asset store package, simply wire me to my paypal account the cost of the package, and I'll create the custom actions to go with it.

bye,

 Jean

Jake

  • Junior Playmaker
  • **
  • Posts: 61
    • Fluffy Underware
Re: "IEnumerator Start()" equivalence in action
« Reply #8 on: May 09, 2013, 02:49:21 AM »
it's not allowed to shared packages from the asset store.
AssetStore sales are non-exclusive, so it's totally up to me whom I send a copy for free or on what other places I sell or share them, isn't it?

But a skeleton example (even a sketch image) would be enough to understand the design pattern you have in mind, I guess.

Jake

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "IEnumerator Start()" equivalence in action
« Reply #9 on: May 09, 2013, 02:52:47 AM »
Hi,

 Asset store sales are per seat, unless stated otherwise by the publisher, so you are not allowed to redistribute for free something you paid, even to a fellow developer, else the publisher is spoiled. Are you the author of Curvy?! that would be a different thing all together of course...

yes, send me a sketch, we'll take it from there.

bye,

 Jean

Jake

  • Junior Playmaker
  • **
  • Posts: 61
    • Fluffy Underware
Re: "IEnumerator Start()" equivalence in action
« Reply #10 on: May 09, 2013, 09:23:37 AM »
Are you the author of Curvy?!
Of course, I thought you know  :D I'll send you a mail soon...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "IEnumerator Start()" equivalence in action
« Reply #11 on: May 10, 2013, 05:39:57 AM »
Hi,

No I didn't  :P  Send it over :)

bye,

 Jean