playMaker

Author Topic: To attach a FSM template to an object in Runtime  (Read 4335 times)

sama.van

  • Playmaker Newbie
  • *
  • Posts: 19
    • Folio
To attach a FSM template to an object in Runtime
« on: September 04, 2011, 12:21:43 AM »
Hi!

I would like to know if there is a way to attach a FSM Template at runtime on a target object.

That is a template FSM script it has to be dropped on too many objects and it would be better if I could do that during the first "loading" process!!

In the Script Control section I found the "Add Script" action that lets me choose "PlaymakerFSM" as Script attribute... But I do not understand how to use it O_o... Or maybe what is that really for...

Does someone could say more about it?  ??? :-[

Thank you much! :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: To attach a FSM template to an object in Runtime
« Reply #1 on: September 04, 2011, 08:21:32 AM »
Hi,

 I am thinking of one way to do it, will do some test over the next few days to validate this:

 basically, instead of attaching a fsm, I would create a prefab that I would simply add to the hierarchy of the targeted GameObject, and have the fsm system access its parent and reference it that way. Then you avoid problems of creating fsms at runtime. I actually do that already on one of my project but nevery really extracted the pattern clearly.



 Bye,

 Jean

sama.van

  • Playmaker Newbie
  • *
  • Posts: 19
    • Folio
Re: To attach a FSM template to an object in Runtime
« Reply #2 on: September 04, 2011, 01:30:35 PM »
hi Jean!

Thank you much!!

Well this afternoon I did an attempt to convert PM the script to a full C# script.

Then I did a loop with PM and the "AttachScript" action and it works very good!!


Now one more problem.....

The action is about more than 80 loops (and will have more later...)

And it seems PM stop looping if over than 50 loops!!! O__O .....

Well here is the screen you can read the max loop ("ChildCount") and the current loop ("i") when it just stop and print the warning at the bottom  >:(

Then if this is an PM issue, I will also re-writte this script with some C# ....  :-[


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: To attach a FSM template to an object in Runtime
« Reply #3 on: September 04, 2011, 04:11:44 PM »
There's an "Infinite Loop Threshold" in Preferences that you can make bigger. It can be easy in visual scripting tools to accidentally make an infinite loop that would hang Unity - this setting lets you recover from that (the default is probably a little low!).

About the original question, the prefab or attach script solutions are probably your best options now. I'd like to support attaching of fsm templates in a future update (also so you can have FSM instances that update when you update the template).

sama.van

  • Playmaker Newbie
  • *
  • Posts: 19
    • Folio
Re: To attach a FSM template to an object in Runtime
« Reply #4 on: September 04, 2011, 08:31:14 PM »
Oh! Thank you much!!!

It was on 100 and it seems to be ok with 300!! ^_^!!!

Yeah coooooool!!!  ;)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: To attach a FSM template to an object in Runtime
« Reply #5 on: September 05, 2011, 02:35:55 AM »
Hi,

 Uhm. I think it should maybe have a different approach to avoid long loops.

Instead of doing this in one fsm. split it so that you have one fsm responsible for a given task that is iterated in another fsm. You communicate via a pair of events : "DO THIS" and "THIS IS DONE" ( you get the point...)

 then you avoid all together any unwanted hog and loops.

 If you need a more precise working example, shout :)

 Bye,

 Jean