playMaker

Author Topic: Global Variable Not Found on Some Actions? [SOLVED]  (Read 4024 times)

mTruly

  • Junior Playmaker
  • **
  • Posts: 98
Global Variable Not Found on Some Actions? [SOLVED]
« on: April 01, 2016, 04:05:04 PM »
I have a global variable called 'animation_name' that is used in many, many actions successfully.  This global variable defines which animation to use.

But I have a few actions that have started to throw errors that it can't find the animation.  (See the attached screengrabs).

Any idea why this variable (that was working fine earlier) can't be found now?

Thanks!
« Last Edit: April 02, 2016, 11:06:32 AM by mTruly »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Global Variable Not Found on Some Actions?
« Reply #1 on: April 01, 2016, 04:21:11 PM »
From the errors it seems like 'animation_name' is set to an empty string.

I would double check any actions that set 'animation_name'. And check "Debug" at the bottom of the State Inspector to keep an eye on variable values as you run the game.

Also check that you don't have any local variables called 'animation_name' in those FSMs. Local variables will be found before global variables.

mTruly

  • Junior Playmaker
  • **
  • Posts: 98
Re: Global Variable Not Found on Some Actions?
« Reply #2 on: April 01, 2016, 05:34:11 PM »
Thanks very much for the ideas!

'animation_name' (the global variable) is used 25 times in the scene according to the Globals dialog.  I have searched for (is there an automated way?) a local variable 'animation_name' and I can't find one.

I have another FSM with 2 states which controls two UI buttons which when clicked, will switch the value of 'animation_name' between Anim_A and Anim_B (see screengrab).  With debug ON, I'm not seeing a value in the GV value slot and it seems like I should.

Yet this is the only FSM where that GV 'animation_name' variable is set.

Thanks!

This works great with at least 22 of the actions but for some reason these

mTruly

  • Junior Playmaker
  • **
  • Posts: 98
Re: Global Variable Not Found on Some Actions?
« Reply #3 on: April 01, 2016, 06:09:00 PM »
Here's a screengrab in PLAY mode showing the global variable is being properly set.  This FSM is the only place that set's it.

Thanks!

mTruly

  • Junior Playmaker
  • **
  • Posts: 98
Re: Global Variable Not Found on Some Actions?
« Reply #4 on: April 01, 2016, 06:33:12 PM »
OK, when I created the global string variable (GV) I made the value 'no name'.

Then in the posts above, showed the FSM action properly setting the GV string value to the desired name.

Then I noticed the warning saying 'no name' was being used instead of the desired name 'valve_OPEN_animation_dupe' (see screengrab).

So something is definitely wacked.

Thanks!


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Global Variable Not Found on Some Actions?
« Reply #5 on: April 01, 2016, 08:01:35 PM »
Do you have FSMs on different GameObjects running in the same frame? The order in which GameObjects are updated is not guaranteed in Unity, so maybe the variable isn't set when some FSMs run...?

mTruly

  • Junior Playmaker
  • **
  • Posts: 98
Re: Global Variable Not Found on Some Actions?
« Reply #6 on: April 02, 2016, 09:30:55 AM »
I'm not sure... I think so... I'm a newbie.

I have many FSMs on different objects.  Only one FSM that sets the 'animation_name' global variable and it seems to be setting it properly.

But there seem to be 3 actions (out of 25) which are not getting the proper variable value (and seem to be retaining the original value).

As to when the FSMs run (and when the GV is grabbed), I don't know how to make them run on any frame other than the first frame.  Is there a way to ensure that the FSM which sets the GV is run absolutely first?  So that hopefully all later FSMs that use 'animation_name' will get the correct value?

The weird thing is... this worked fine with no errors for a long time.  I must have been fixing something else when I did something and this broke and I didn't notice it until later when I saw the errors.

Thanks again.

mTruly

  • Junior Playmaker
  • **
  • Posts: 98
Re: Global Variable Not Found on Some Actions? [SOLVED]
« Reply #7 on: April 02, 2016, 11:05:23 AM »
OK, I got it solved.

The FSM containing the Set String Value which set the global variable 'animation_name' was on an empty game object nested down in a canvas object where all the buttons live (since I want to be able to hide the canvas and thus, hide the buttons on the canvas).

But it seems having this FSM down there made certain FSMs get the global variable before that FSM had been run, so they got the original value of the global variable 'no name'.

When I moved the empty game object, which contains the global variable setting FSM, to the root level of the hierarchy... this FSM was run first and then the 3 other actions correctly get the desired global variable value.

Thanks again!

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Global Variable Not Found on Some Actions? [SOLVED]
« Reply #8 on: April 02, 2016, 01:13:45 PM »
Glad you solved it. However, be aware that Unity doesn't make any guarantees about the order in which GameObjects are updated. From the Unity docs:

Quote
By default, the Awake, OnEnable and Update functions of different scripts are called in the order the scripts are loaded (which is arbitrary)

So it could break again in the future or on another platform etc.

If you have a specific order you need FSMs to follow, or one FSM that needs to run first, it's best to enforce that explicitly.

For example, the FSM that initializes some global variables could broadcast an event "Initialized" that other FSMs are waiting for. Or it could enable other dependent GameObjects after initializing the global variable.

mTruly

  • Junior Playmaker
  • **
  • Posts: 98
Re: Global Variable Not Found on Some Actions? [SOLVED]
« Reply #9 on: April 02, 2016, 03:41:46 PM »
Thanks very much for this info.

I will have to look deeper into this to try and make it more bulletproof.

Thanks again.

mTruly

  • Junior Playmaker
  • **
  • Posts: 98
Re: Global Variable Not Found on Some Actions? [SOLVED]
« Reply #10 on: April 03, 2016, 11:23:11 PM »
Hmmm... it did actually break again.  So I fixed it with a Send Event Broadcast and now it seems to be working great.

Thanks again.