# Two Questions Random Images On Buttons

**URL:** <https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255>\
**Category:** UI\
**Tags:** randomize-array, unreal-engine, Widget, Blueprint, question\
**Created:** [March 14, 2021, 3:44am UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255 "2021-03-14T03:44:30Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_86f4b4551](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86f4b4551](https://forums.unrealengine.com/u/anonymous_user_86f4b4551)\
**Post date:** [March 14, 2021, 3:44am UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/1 "2021-03-14T03:44:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 14, 2021, 10:00am UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/2 "2021-03-14T10:00:08Z")

</div>

> 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:

 ![332402-01.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/2/5/b25232f30343b2a012dfb6166b5ae5627a6c953c.jpeg)

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/2/3/f23c8e98485506d667d10c51cec6ea96408ee330.jpeg)

So in the GI, you could:

![332404-screenshot-3.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/9/f/39f1d360fd876645ed8ca2cbbc654bb2c651a0f3.jpeg)

> 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:

 ![332405-switch.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/b/1/3b1400b8476854b31c6e665d97288fe4834e2aae.jpeg)

- or

![332406-screenshot-4.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/1/c/b1c15ea55d595ca21b5045a8a3adf45e908f93c3.jpeg)

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_86f4b4551](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86f4b4551](https://forums.unrealengine.com/u/anonymous_user_86f4b4551)\
**Post date:** [March 14, 2021, 1:58pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/3 "2021-03-14T13:58:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_86f4b4551](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86f4b4551](https://forums.unrealengine.com/u/anonymous_user_86f4b4551)\
**Post date:** [March 14, 2021, 2:17pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/4 "2021-03-14T14:17:07Z")

</div>

[Screenshot - b8ec0b9b9807b8f900187103fb42b525 - Gyazo](https://gyazo.com/b8ec0b9b9807b8f900187103fb42b525) [Screenshot - 131c7d8c274562c1e9ca94600eec19c7 - Gyazo](https://gyazo.com/131c7d8c274562c1e9ca94600eec19c7) [Screenshot - 269eef2c21d406516eb562ffb68f3ace - Gyazo](https://gyazo.com/269eef2c21d406516eb562ffb68f3ace)  
[Screenshot - 759da66069ce10bfadaf9041087cd1eb - Gyazo](https://gyazo.com/759da66069ce10bfadaf9041087cd1eb)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 14, 2021, 3:07pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/5 "2021-03-14T15:07:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_86f4b4551](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86f4b4551](https://forums.unrealengine.com/u/anonymous_user_86f4b4551)\
**Post date:** [March 14, 2021, 3:12pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/6 "2021-03-14T15:12:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_86f4b4551](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86f4b4551](https://forums.unrealengine.com/u/anonymous_user_86f4b4551)\
**Post date:** [March 14, 2021, 3:45pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/7 "2021-03-14T15:45:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_86f4b4551](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86f4b4551](https://forums.unrealengine.com/u/anonymous_user_86f4b4551)\
**Post date:** [March 14, 2021, 5:50pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/8 "2021-03-14T17:50:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 14, 2021, 7:36pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/9 "2021-03-14T19:36:57Z")

</div>

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*`

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_86f4b4551](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86f4b4551](https://forums.unrealengine.com/u/anonymous_user_86f4b4551)\
**Post date:** [March 14, 2021, 8:55pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/10 "2021-03-14T20:55:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_86f4b4551](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86f4b4551](https://forums.unrealengine.com/u/anonymous_user_86f4b4551)\
**Post date:** [March 14, 2021, 9:49pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/11 "2021-03-14T21:49:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 14, 2021, 10:53pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/12 "2021-03-14T22:53:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_86f4b4551](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86f4b4551](https://forums.unrealengine.com/u/anonymous_user_86f4b4551)\
**Post date:** [March 15, 2021, 1:04pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/13 "2021-03-15T13:04:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 15, 2021, 1:19pm UTC](https://forums.unrealengine.com/t/two-questions-random-images-on-buttons/480255/14 "2021-03-15T13:19:52Z")

</div>

Aye, sleep is underrated!
