playMaker

Author Topic: [Newbie] Checking the change of a boolean variable on a script  (Read 5629 times)

kurai

  • Playmaker Newbie
  • *
  • Posts: 9
[Newbie] Checking the change of a boolean variable on a script
« on: February 14, 2013, 04:37:13 AM »
Hi there,
I'm just getting the hang with Playmaker, so please, bear with me. It's probably a newbie question.

The scenario: I have a game object with a C# script doing some controls. When a certain combination of events occur, a boolean var becomes true.

I want my FSM attached to the object to change state, so I made a series of actions which basically control the variable and fire up the transition when it becomes true. I put here a screenshot of the actions for your convenience.



Now, this setup seems to be working correctly only when I make the check on Every Frame.

I have two questions for you:

1) Is this setup going to affect my performances a lot?
2) I guess it won't be necessary to constantly control this stuff, but I don't know another way to tell the FSM something has changed in a script. Have you any suggestion on how to improve this?

Thank you!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: [Newbie] Checking the change of a boolean variable on a script
« Reply #1 on: February 15, 2013, 02:57:46 AM »
Hi,

 I would try using "bool changed" action instead. I think it's more appropriate here.

 as far as performances, It's a common practice to "watch" variables every frame and I don't really see anything wrong with what you are doing.

what is bad is using the "Find GameObject" actions every frame for example as the find method of Unity is not optimized. but accessing variables is fine really.

It's of course better to use more "event" based systems, especially for boolean, instead of having a bool your system could fire an event when it knows it changed, it prevents multiple instances to watch for this bool, when they can simply wait for an event to occur.

does that make sense?


bye,

 Jean

kurai

  • Playmaker Newbie
  • *
  • Posts: 9
Re: [Newbie] Checking the change of a boolean variable on a script
« Reply #2 on: February 15, 2013, 08:56:01 AM »
Yes, completely. Thank you for make it clear for me.