playMaker

Author Topic: Get Animator Current State + Global Variable  (Read 1425 times)

spektron

  • Playmaker Newbie
  • *
  • Posts: 6
Get Animator Current State + Global Variable
« on: June 09, 2018, 02:14:35 PM »
Hello,
I use the action "Get Animator Current State Is Name" to get the state name and compare it.
If I drag the GameObject directly from the hierarchy, all ok
BUT
if i have the GameObject passed as Global variable, the action doesnt get any info.
Note that the GameObject has an action "Get Owner" that save it in the global variable directly when it spawn.

I'm confused why the animator action doesnt work with the global variable.
any help?

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: Get Animator Current State + Global Variable
« Reply #1 on: June 09, 2018, 05:13:16 PM »
So when you specify a game object for this action by using a global variable where a GO should be stored, then run and use the action, it cannot find any state's name to return, as if it could not read (scan) the GO or not see that it has an Animator component?...
I think PlayMaker devs advise against using globals as often as possible, right?

You could emulate a global var though.
Use instead a separate FSM on an empty "manager" game object that has a FsmGO var where you could store the GO.
So instead of using a global var, the GO that is spawned and which, I guess, has a FSM that starts automatically on wake up, would have an action "Set FSM Game Object" that stores itself, the owner, into the FsmGO of the idling "manager" FSM.

Using FsmVars that way is better imho because it allows you to have a better view of the variables' values in the inspector. Despite being theoretically more exposed than "local" FsmVars (which are in fact equally public/exposed as far as I'm concerned), global vars are insufferably opaque and hard to keep tabs on.
Besides, FsmVars are easy to rename, which isn't the case with globals.

spektron

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Get Animator Current State + Global Variable
« Reply #2 on: June 09, 2018, 05:31:49 PM »
Thanks for the reply!
Agree with the global variable usage, but this was just a quick test.

Usually the issue is that I have 2 FSM, 1 with the "Get Owner" action that save to global and 1 that asks for that global variable to access the GO.
They both start at runtime so the second FSM may be too quick to access the global variable that is not written yet. I solve this by having a small delay in the second FSM.

This all to say that in the case of the "Get Animator Current State Is Name" action, this is not solved as written above. Nor with your suggestion.
it only works if I drag directly the GO from the hierarchy.

I'm a bit puzzled by that.

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: Get Animator Current State + Global Variable
« Reply #3 on: June 09, 2018, 06:26:03 PM »
Oh, that's weird then.
In the ahem "solution" I presented above, you'd just have to get the variable from the FSM that's used like a storage, a place to keep track of a certain number of variables.
I never had problems with this method but then I hardly used the action you are having problems with. :/

Perhaps there's a silly mistake that's easy to miss?
Or... you use Get Animator Current State Is Name, but there's a similar action that also allows you to recover the state's name: Get Animator Current State Info. It's almost the same, minus the internal comparison test.
So you have to save the name in a string and then compare strings.
It's one extra step but maybe that action will work?