playMaker

Author Topic: iterating over and modifying custom actions  (Read 1351 times)

mental.breakdance

  • Playmaker Newbie
  • *
  • Posts: 8
    • View Profile
iterating over and modifying custom actions
« on: January 22, 2013, 05:48:30 PM »
Hi all,

Just a code question here, and how best to manipulate Actions from external code. On our team we have a couple of designers who are building FSMs and as a programmer, I can just facilitate them by adding new Actions when needed. A rather nice arrangement so far! :)

However, as some of these new actions have dependencies on some of our systems, I'm looking into ways of setting the required data/pointers/etc on the actions via code, so that the designers don't have to drag a bunch of random game objects onto the action every time they use them. I'd like to avoid the use of singletons and just have their dependencies set externally if possible (i.e. dependency injection).

As such, would it be considered misuse of PlayMaker to do the following in a 'manager' class:

  • find all FSMs in the scene
  • iterate across all states in each fsm
  • for each state, iterate across all actions
  • if an action is a custom one with dependencies, set them via a property

Obviously it's a very expensive call, but it would only be called once on initialisation. I'd be interested to hear if anyone else has done something similar or has a better idea on how to do it.

Thanks!

mental.breakdance

  • Playmaker Newbie
  • *
  • Posts: 8
    • View Profile
Re: iterating over and modifying custom actions
« Reply #1 on: January 23, 2013, 08:33:44 PM »
One problem that I've found is that this doesn't work if the fsm is on a game object that is deactivated - at that point I can access all the FsmStates on it, but trying to access the FsmStateActions on that returns an error because the State is not initialized.

Is there any way of registering with an 'OnInitialized' event (or equivalent) on an fsm?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: iterating over and modifying custom actions
« Reply #2 on: January 24, 2013, 06:24:52 AM »
Hi,

What I would used instead is some static variables or methods that you define in your various scripts, and then you can can access them within your playmaker actions easily.

 Remember that within an action, you have a pointer to the gameObject of this fsm component, and you can simply get any other components attached on that gameObject, and thus you are within the very same environment as any other non playmaker scripts.

does that make sense?


bye,

 Jean