playMaker

Author Topic: Setting UI Text within prefab  (Read 2174 times)

topscore1632

  • Playmaker Newbie
  • *
  • Posts: 19
Setting UI Text within prefab
« on: July 15, 2016, 11:01:09 AM »
Hello everyone

I have some UI text which I need to be duplicated a number of times in my game and displayed and updated simultaneously. I've therefore made it a prefab and am trying to use Set Property to update the text. However, the text does not update - the FSM works fine if I use it on a standard GUI Text object, but if I make that same object into a Prefab and try it it doesn't work.

Is what I'm trying to do even possible?

Thanks!

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: Setting UI Text within prefab
« Reply #1 on: July 15, 2016, 03:32:40 PM »
Hi,

(Edit:)
I think the best solution to your issue is to put the 'set text' action on the prefab in a state which has a global transition into it. This global event/transition should be a unique event, which you will send each time you want to change text. In the 'set text' action, set it up so that a global string variable is the text to be set.

Then the FSM that changes text, just sets the global string variable and 'broadcasts to all' the global event which transitions into the state with the 'set text' action.

This way you can avoid arrays and getting owner and such.


(Original reply:)

Basically one way to interact with prefabs is to put the 'get owner' action on the prefab and then use 'set FSM game object' action to communicate which object has the text to the FSM that needs to change the text.

So the prefab gets owner (so self) to a game object variable and then sets that game object variable as a game object variable in the FSM that changes the text. Then the text changing FSM sets the text on the game object variable that was set by the prefab.

(Otherwise you can use a global variable when you 'get owner' and then simply set the text on the global game object variable. Just be careful with this, especially if you want different prefabs to have different texts)

However I think for your situation you will also need to look into array maker to make things simpler. This is because you want to interact with multiple objects and it will be easier to do so with a list (array).

Hope that makes sense. :/

I'm a noob so I may be wrong and there may be even more elegant ways to do it, but good luck with it!
« Last Edit: July 15, 2016, 03:45:26 PM by Zeldag »

terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: Setting UI Text within prefab
« Reply #2 on: July 15, 2016, 06:33:43 PM »
have you tried using the U Gui Text Set Text action?

topscore1632

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Setting UI Text within prefab
« Reply #3 on: July 18, 2016, 05:19:12 AM »
Cheers for the suggestion Zelda I will give that a go :)