Download

Trying to display a random image and its name from an array

I’m trying to make a game that relies on displaying random images from an array to the player. I was able to randomize and display the images in the array just fine, but I also wanted to print out in a box something along the lines of “you found [insert image name here]” upon clicking a button, but the name of the image seems to also get randomized, so the image name isn’t lining up with the image itself.

So my question is: How do I display an image from an array and also display the name of the image?

I’m fairly new to Unreal, so any help will be accepted.

You are probably running the randomize twice when getting the image and then the name. If you share what you have then perhaps we could be of more help.

This is what I have.

So what @pezzott1 said is basically what is happening. Pure nodes (those without the white exec pins) are a little weird and are evaluated from scratch every time. So when ‘Set Brush from Texture’ tries to get it’s input, the ‘Get’ is checked and it pulls a random number from the ‘Random in Range’. Then when ‘Set Text’ gets it’s text input, it traces back to the ‘Get’ a second time which gets a new random number from ‘Random in Range’.

You’ve got to simplify the ‘Get’ so that it only has one connection to the out pin to get the functionality you want.
Option 1) Create a new variable, assign the result of ‘Get’ to it and then pass that variable into the two Set functions.
Option 2) Move the two set functions into your own function which takes the texture as a parameter.
Option 3) Move the whole thing into your own function, assign the result of ‘Get’ to a local variable and then pass that variable to the two Set functions.

1 Like

I think that Option 2 would be my best bet. I’ll try that right now and see if it works, thanks.

Your 2nd option worked! It now randomizes them correctly! Thanks to you both, your help is greatly appreciated.

1 Like