I currently have a function which selects a random number of items from my data table. The items have a corresponding image. Within this function i have a “make array” which records the results
I want to display images of all the selected items however currently only the first item (out of 3 selections for example) is displayed. I think it involves using a for each loop of some sort but i dont know where to input it
Essentially, rather than faffing around with randoms, we shuffle the array, grab the first x elements and return them. This way we do not need to worry about repetitions. Unless you desire / allow repetitions, ofc.
Ideally, you’d add a bounds check in case you try to pull more than the DT contains. May be irrelevant.
thanks alot for replying! I might have not explained what I meant properly sorry I am completely new to using UE5. The function to pull the random items itself works but i cant seem to output the multiple results (images) at once. Instead only one appears which is the first item out of the list of randomly selected items
I am only able to embed one image per reply it seems so ive included the one i think needs tweaking?
Instead of the Name variable, use the variable type you desire. Potion Image is, most likely, Texture2D.
I didnt add the shuffle as i dont mind repetitions.
There is no randomisation whatsoever now then. If you want randoms with repetitions, this needs to be done differently, get a Random element from the DT and add it to the array.
Also a strange thing is happening which im not sure why, if i have the return node connected i will be able to output the image however it is always 3 random selections (based on the print string). If I do not then it randomly selects as expected (e.g. i got 6 in the screenshot below) but no image will appear. I will be posting as a seperate reply as i cant attach more than one image
It only exists (is in scope) for as along as the function is running. The next time the function runs, there will be an empty array to work with, without the need to clear it first. I see you’re using it in your example, just wanted to highlight it.
THANKS SO MUCH I finally got it to work with your help! Ive uploaded an image of the result where im now able to get multiple images at once to display. I added a print string just to check and its out putting those 4 images. I will upload my other widgets just to show u perhaps you can give me your opinion on whether I did it in a efficient way as i feel i am not.
Thanks again for all your patience, your annotation on your previous image explaining the process of how to set out the nodes really helped with my understanding
This is my widget which i put together to output the image, essentially i have a bunch of “set brush from texture” for each image component. not sure if thats the best way to do it