I am new to UE, and had a go at creating a set of 5 random x,y coordinates (x and y in range 1-8) as my first attempt in blueprinting. No problem, it works.
What I haven’t attempted to do yet is to make sure none of the 5 points has been repeated, so I want 5 unique positions on a chess board, and each time you play it generates a new set.
Is there a simple way of achieving this workflow in a blueprint? Wondering what sort of options I have.
(p.s. Later I might want to modify the same code to give me only 1 or N number of unique coords, so ideally it would be flexible)
One method I am thinking of is placing all the 64 vector2 coords (1,1), …,(8,8) into an array, and then shuffle them about, and then just take the first 5 coords (or N coords) in the new array. (Could also just use the numbers 1 - 64 to simplify it.)
Alternatively, I could set up a board array, when the coord is chosen I check the array’s boolean, if it was False, then I use that coord, and set it to true. If it was already True, I circle back around and create a new random coord.
Are there any better/proper/standard/more obvious ways of doing this?
I eventually worked out a method of looping through for the required number of random numbers followed by a large loop until random number is not in list of existing random numbers.
One thing that had me stumped for days was that I was setting the array item when it was unique, yet it was not printing out any resultant numbers. It turned out that in order to set an array item it had to have been initialised, so I either had to initialise each array item in the variable section, or ‘add’ the array values rather than set them.
I noticed that option but didn’t think it would help me.
I ended up hard coding 5 initialised array items, which is fine for this first version of my program, but ideally I’d like to have that number variable, so that sounds like it would help.