playMaker

Author Topic: Global variable issues [SOLVED]  (Read 1471 times)

homeworld

  • Playmaker Newbie
  • *
  • Posts: 39
Global variable issues [SOLVED]
« on: September 02, 2017, 02:36:51 PM »
Hi! I've been hitting a wall working on this today, hopefully someone can shed some light! I'm storing an UI element gameobject into a global variable at runtime, and then trying to modify its scale from a bunch of prefabs. It's a progress bar for hacking enemies, and the enemies need to talk to the UI and scale the progress bar as they're getting hacked.

It doesn't seem to matter if the enemies are instanced or not, it seems like the only one who can actually scale the UI progress bar like it's supposed to is the last one added to the hierarchy.

It seems like the enemy FSMs actually pick up the global they're supposed to, but for some reason the scale fails; very confusing! Any ideas about why this happens would be highly appreciated!
« Last Edit: September 03, 2017, 10:17:46 AM by homeworld »

Deek

  • Full Member
  • ***
  • Posts: 133
Re: Global variable issues
« Reply #1 on: September 03, 2017, 08:12:40 AM »
Your enemies likely change the scale of that UI Element every frame and if you have more than one enemy in the scene, they fight for different scales at the same time.

Example: Enemy 1 changes the scale to 1 every frame and Enemy 2 changes it to 2 every frame. Because they both try it at the same time, a conflict happens (at least that's how I understood your scenario).

So a working approach would be to create a new GameObject in your scene which is unique (maybe call it something like "UIHackingProgressManager") and have it manage the scale of that UI Element, while the Enemies only pass the new scale value to it (either through Global Variables or 'Set FSM Float'). That way there's only one FSM controlling the scaling and the enemies only give him the information to what scale it should animate.

If that was not the problem or didn't solve it, please elaborate further or in more detail.

homeworld

  • Playmaker Newbie
  • *
  • Posts: 39
Re: Global variable issues
« Reply #2 on: September 03, 2017, 10:17:24 AM »
You're right!! That didn't occur to me at all; once i stop the hacking process, and the hacking progress goes back to zero, i'm able to target any other target and the progress bar behaves as expected!

I'm relieved to hear that the problem wasn't with my understanding of global variables; i'll go ahead and take your advice about making a centralized ui manager for that progress bar! Thank you VERY MUCH!!