playMaker

Author Topic: Strange Global Var Behavior - Works After Second Run[SOLVED]  (Read 1958 times)

memetic arts

  • Full Member
  • ***
  • Posts: 141
Okay, this one is really hanging me up . . . hopefully it's something stupid and someone out there can set me straight.

I have a prefab with an NGUI UITexture on it.  The prefab has several manually instantiated objects in the scene (not generated at runtime).  There is also a set of buttons representing texture options.  The desired functionality is to click a button and change the texture on the instantiated objects.  Simple enough.

I've got an FSM on each button, which, on click, gets the value of its texture, stores it in a global var, and then sets the texture on the prefab with the global var value.  This seems to work, but ONLY after running the app for the second time.  On the first try after opening the project/scene, absolutely nothing happens.  As soon as I hit "stop", the textures all change to what they should have been when I clicked the button.  And from then on, as I said, everything works as expected.

I'm guessing that the issue has to do with initializing the global var, and I've tried several approaches at doing that, but none have succeeded.

I've also tried sending events to the prefab so that it would set itself, but couldn't get that to work either,no idea why.

Any assistance here would be greatly appreciated!

Thanks!
« Last Edit: May 16, 2013, 11:58:40 AM by memetic arts »

memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: Strange Global Var Behavior - Works After Second Run[SOLVED]
« Reply #1 on: May 16, 2013, 11:58:14 AM »
Finally solved this one . . . apparently was, indeed, an initialization issue, resolved by somehow getting Send Event to work . . . I think the trick was to use "broadcast all" vs. to a specific game object FSM.

I think a little sleep helped as well . . .

And for other relative newbies like me, the underlying lesson here is that the most direct way to set props on a prefab is to include all of the Set Property actions on the prefab itself, and trigger them with a global "broadcast all" event, to which only the prefab is listens for.

cheers . . .