playMaker

Poll

is AttachFSM on fly important?

yes
8 (100%)
no
0 (0%)

Total Members Voted: 8

Author Topic: Attach FSM on fly  (Read 7144 times)

aliessmael

  • Playmaker Newbie
  • *
  • Posts: 26
Attach FSM on fly
« on: February 02, 2012, 11:40:31 AM »
I think this feature is very important.
because now i am working in crowd AI , and i need to change agent behavior according to the environment and event around him.
for example if i did FSM for agent to make him go from spawn1 to spawn2.
what if i need to stop him and speak to him , what if car hit him , what if some one shoot him?
to do that ( for car hitting example ) , the car FSM will pause current agent FSM and attach another FSM to make him interact with car. after that the car could Deattach the FSM and continue old one?


actually i tried to do that but the problem is the template is made from FsmTemplate class which is defined in PlayMakerEditor.dll.

i tried to put my template in resource folder and load it to FsmTemplate which is defined in PlayMaker namespace , but the loading failed


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Attach FSM on fly
« Reply #1 on: February 02, 2012, 12:19:10 PM »
I'll look into this for the next update. Bare in mind you should avoid making too many objects while the game is playing. It's better to make objects on load then re-use them or turn them on/off. So in your example, it's probably more efficient to attach all the FSMs to the car, load them once, then turn them on/off as needed using Enable Behaviour or Enable FSM.

aliessmael

  • Playmaker Newbie
  • *
  • Posts: 26
Re: Attach FSM on fly
« Reply #2 on: February 02, 2012, 02:40:46 PM »
my idea of car example is Attach Fsm on fly could make management of my FSMs better.

let us say i did agent with Walk FSM.
if there is new feature like if explosion happen near him his behavior should be changed to Scare FSM
without Attach Fsm on fly , i have to create Scare FSM on agent
finally for each new feature i have to add new FSM to the agent , or i have to modify old one
and i have to manage enable disable for them

now what if i have to make new feature for specific level or scene
what if i use this agent as common prefab for any scene or level

with Attach Fsm on fly i will do like this
i will create agent with Walk FSM
if explosion happen near him , explosion object will pause FSMs for all object which has WalkFSM and attach Scare FSM on fly
the new feature ( explosion ) is responsible to attach new feature behavior
no need to change agent FSMs at all.
new feature or new interactive object is responsible about changing behavior

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Attach FSM on fly
« Reply #3 on: February 02, 2012, 02:54:17 PM »
Good point. I'm still worried that you'd see performance hitches if you did a lot of this... but I agree, the feature is useful and we'll try to add it. The end user can then make the performance/design trade-offs that they're comfortable with.

aliessmael

  • Playmaker Newbie
  • *
  • Posts: 26
Re: Attach FSM on fly
« Reply #4 on: February 03, 2012, 02:09:29 AM »
for performance , you are right
may be instead of loading FsmTemplate on fly.
i could do like this.

i apply disabled Scare FSM to explosion Object in build time.
then i can copy it on fly from this object to agent. may be this will be faster.

actually i did CopyFsmFromGameObject , it succeed , but i face one problem.
when i call  gameObject.AddComponent<PlayMakerFSM>() it give error, because PlayMakerFSM is trying
to access uninitialized data.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Attach FSM on fly
« Reply #5 on: February 13, 2012, 02:02:28 AM »
Hi,

 I agree, it could be a nice feature, but actually I think there is a way to go around this, by reversing the process, or better said, build a small framework.

 instead of attaching a crowd behavior to an agent directly. Some kind of crowd broker could be created that for each behavior will create a an empty gameObject ( from a prefab) with all the logic to control an agent for a specific task.

 So the agent is not responsible for the logic, but actually this prefab ( that was feed the agent to control). So you would have a prefab to walk a target, a prefab to scare a target, etc etc.

Then, you can apply/manage behaviors to an agent and mix them at will without adding removing fsm on the agent itself, but actually adding and removing gameObject prefab responsible for a specific behavior.

 It might result in the same performance hit as adding a component tho ( iTween suffer from this too).

Hope this make sense :)

 Bye,

 Jean

aliessmael

  • Playmaker Newbie
  • *
  • Posts: 26
Re: Attach FSM on fly
« Reply #6 on: February 13, 2012, 07:50:19 AM »
yeaa , it is good idea.
but you know there is one problem.
what if scare behavior must pause all old behavior then when scare finish it will resume it again.
it will be difficult to search for all game object which control target object to pause them.

but may be if these empty game objects which control a target become as children of target with specific names. it will be nice.

so if we add FSM on target which is responsible to search for these object and run the last one and pause the previous ones. in this case we can implement (push ,pop) for behaviors.

yeees i like it.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Attach FSM on fly
« Reply #7 on: February 14, 2012, 02:25:30 AM »
Hi,

 yes, good thinking, parenting is a good way to go about this.

 Bye,

 Jean

Gua

  • Beta Group
  • Sr. Member
  • *
  • Posts: 309
    • Andrii Vintsevych
Re: Attach FSM on fly
« Reply #8 on: February 13, 2014, 12:24:14 PM »
Was this feature was made?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Attach FSM on fly
« Reply #9 on: February 13, 2014, 05:43:11 PM »
Krileon posted some actions for this here:
http://hutonggames.com/playmakerforum/index.php?topic=5819.msg28493#msg28493

These should probably be in the Share New Actions section...

Gua

  • Beta Group
  • Sr. Member
  • *
  • Posts: 309
    • Andrii Vintsevych
Re: Attach FSM on fly
« Reply #10 on: February 19, 2014, 11:29:39 AM »
Thx. Is there a reason not to make this an official action?