I’m working on a puzzle game project to learn th unreal engine using blueprints and I’ve run into a snag. I have my objects in an object array and I can now separate them based on color and write them to a vector array that only contains objects of that color. All of my pieces land in a grid that snaps them into 100 unit increments x and y. I’m having an issue with coming up with how to detect if four of the vectors from a colour array contain four pieces that are all 100 units from the next one. Basically I’m trying to detect if there are four in a row. Is there a node that could help me do this?
You need to check if you have 4 pieces in a row in array.
For each array element check if it has neighbor at X = +1 and -1 , and y = +1 and -1.
if there is neighbor in some direction just count how many pieces you have in that direction.
To make everything easier:
-every time you move one piece, populate array that has false/true for each grid space. To do so get all actors from class (of your piece) get their locations, divide by 100 and place in 2d array.
you cannot make 2d arrays in unreal, so you need to use onedimensional and create functions to set and read cell and x,y index.
when you have populated array just check each cell in array if its filled, then try 3 neighbors in each direction
Doing it all above on vectors may be easier or more messy depends on implementation.
You could create function that checks if there is neighbor at 100 units distance. For it use trace line at +100,0,100 down to +100,0,-100 (or so) and checks if it hits object that has class same as piece of puzzles.
If you find neighbor there you call another function that asks neighbor to check its neighbor in this same direction and increase some counter. Then return to sender. So you know number of pieces in that direction.
So either you battle arrays or blueprint to blueprint communication.
I think for now I’m going to try the ray cast method, I think I’ll have an easier time coming up with the functions required for this method. I appreciate the input!!