Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on July 15, 2011, 10:09:29 AM

Title: FsmBoolChanged.cs
Post by: jeanfabre on July 15, 2011, 10:09:29 AM
Hi Everyone,

 Just a simple addition to allow for watching a boolean change from another fsm. Very handy to avoid storing duplicate information across fsm.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// Modified by Jean Fabre :
// this is a combination of BoolChanged and GetFsmBool since I don't want the extras steps required otherwise.
// I also don't feel like saving a variable for every single check from other fsm, I want to avoid redundance sometimes.
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
[Tooltip("Tests if the value of a Bool variable from another FSM has changed. Use this to send an event on change")]
public class FsmBoolChanged : FsmStateAction
public FsmOwnerDefault gameObject;
[Tooltip("Optional name of FSM on Game Object")]
public FsmString fsmName;
public FsmString variableName;

public FsmEvent isTrue;
public FsmEvent isFalse;

bool currentValue;
bool previousValue;

GameObject goLastFrame;
PlayMakerFSM fsm;

public override void Reset()
gameObject = null;
fsmName = "";

isTrue = null;
isFalse = null;


public override void OnEnter()

previousValue = currentValue;


public override void OnUpdate()

if (currentValue != previousValue)
if (currentValue){

void DoGetFsmBool()
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;

// only get the fsm component if go has changed

if (go != goLastFrame)
goLastFrame = go;
fsm = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);

if (fsm == null) return;

FsmBool fsmBool = fsm.FsmVariables.GetFsmBool(variableName.Value);

if (fsmBool == null) return;

currentValue = fsmBool.Value;



Title: Re: FsmBoolChanged.cs
Post by: tobbeo on July 15, 2011, 07:33:22 PM
Very cool! I'll be using this a lot, thanks for sharing!