Two Questions Random Images On Buttons

So i have made a random image system for my buttons and i have 2 questions, 1: Instead of it randomly generating everytime the widget appears i only want it to generate a new picture when the level is loaded. 2: How can i make events for the randomly generated pictures? They do randomly generate now but if i get 1 of the 2 pictures i want it to do that and for the other picture i want it to do that etc… how would i do that?

1: Instead of it randomly generating
everytime the widget appears i only
want it to generate a new picture when
the level is loaded

You’d need to generate that value outside of the widget and feed it to the widget during (or after) creation. An exposed variable should work well for this:

  • in the widget:

When you create the widget, you could pull that randomly generated value from the Game Instance (there’s only 1 per session) and feed it to the widget:

332403-screenshot-2.jpg

So in the GI, you could:

332404-screenshot-3.jpg

a new picture when the level is loaded

Have the level generate the value instead of the GI and pipe it into the widget.


Alternatively, you can generate and store that value in a save game. When a widget needs creating, you read it from the save game data. This way, it will be consistent even between sessions.


2: How can i make events for the
randomly generated pictures? They do
randomly generate now but if i get 1
of the 2 pictures i want it to do that
and for the other picture i want it to
do that etc… how would i do that?

Many ways, you could Switch on Int:

  • or

332406-screenshot-4.jpg

  • or, if there’s only 2 values use a Boolean rather than int. The rest still applies.

Is the (Which Image) var and the (Static Random) var the same?

Screenshot - b8ec0b9b9807b8f900187103fb42b525 - Gyazo Screenshot - 131c7d8c274562c1e9ca94600eec19c7 - Gyazo Screenshot - 269eef2c21d406516eb562ffb68f3ace - Gyazo
Screenshot - 759da66069ce10bfadaf9041087cd1eb - Gyazo

But is it set up correctly in the 4 links below? I haven’t begun on the events yet

Cuz it doesn’t seem to work how i have it set up right now as i have gotten only 1 of the images 8 times in a row now but that might just be luck but i do get some errors when exiting the level

No. One is the wiget and the other one in the Game Instance.

I just discovered something, the select node only selects option 0 it never selects option 1 but i don’t know how to fix it

Thanks i got it fixed but the last thing now is to make it so when i press on one image it should change animation blueprint to what it is selected to. I have tried this but it didn’t seem to work

Regarding the error:

How are you setting that variable? Are you using the Game Instance at all? One cannot just create a variable that points to an object and expect it to work. It’s like creating an integer, not setting it to a value and expecting it to be 500. It’s not, it’s 0 (or worse, uninitialised).

Here’s a primer:

The GI is a framework class that persists between levels. Providing you've set it up and are using it, you can then pull its data from any blueprint by `Get Game Instance` -> `Cast To *Your GI Class*`

How are you triggering that event? Something needs to call it, right?

I just tried some print strings on the switch on int and they didn’t print

Ahh man, i was tired last night, my brain wasn’t functioning. Sometimes i just forget the simplest of things, thank you man!

Aye, sleep is underrated!