I am new here and I am a total beginner [in everything gamedev related] but I struggled with this topic for 3 days now and I just have no more ideas. I am taking part in GameJam (as a way to motivate myself to learn) but I got stuck so much I doubt I can finish the project…
I build Procedural Mesh with Blueprint, that is a grid made of lines (based on YT tutorial https://www.youtube.com/watch?v=Q4AOmT9aOEM ). Grid creation works perfectly fine, selecting grids cells is also perfect, as well as saving all the selected cells in the past (so if I click somewhere on a grid it changes material to red and keeps it saved, so you know, where you already clicked). The selected cells are saved into the Gather Points array [Global], which is Array of 2D vectors, out of which X represents the row and Y the column of chosen grid cell. Clicked cells are added to the array based on mouse left key release node - when I release the left button, it runs the script for creating those points mesh.
When I try to remove the vector (X [Row] vs Y [Column]) from Gather Points Array it doesn’t get removed. I tested multiple solutions and ideas, and I ended up still having the problem, and nowhere closer to solution.
What I have now?
Right now I first check, if the selected cell is already in the Gather Points Array. Based on it I use Branch Node - if the cell [2D Vector] is already in Gather Point Array it should be removed and mesh should be generated. If the 2D Vector is not yet in array it should be added and the mesh should be procedurally generated. I checked, and it finds the index of existing vector properly (-1 when it doesn’t exist in Array, and 0-n if it exists). However, there is no visible effect of it - or at least not in a good way. It either has no impact at all or doesn’t create the mesh at all in the first place.
What I believe is a problem:
After multiple variables checks and analysing all the results for many different versions of this blueprint I came to conclusion, that that function is called twice. I feel that way as every time I printed for example the index of element, it printed the result twice, and the result was not necessarily the same. I
t seems that every time, that there is no vector in the array - it adds it, but then it runs again and removes it, so in the end it is not in the array.
Alternatively, if the vector already exists in the array - it removes it, but then it adds it again. I might be wrong of course, but this is how it looked for me when I was making multiple tests over the past 3 days.
I believe I am either unfamiliar with some conditions required by procedural mesh (maybe the global variable storing the visited cells is a problem here? maybe when global variable gets updated it causes to call a function second time? On the other hand I tried my chances with Local variable and the result was the same, so…) or I am doing some logical error when it comes to using global and local variables.
I attach a picture with my Blueprint. Don’t worry that exec is not connected - I disconnected it on purpose, as every time I connected this function whole blueprint was incorrect and didn’t save new vectors at all. When I was checking, if the index exists, in printed (every time) the result of -1 and 1, so after one “print string” node I got 2 indexes.
I hope I explained it well, but please, feel free to ask me anything. I need to finish the project by the 22nd Nov if I want to take part in this jam.
EDIT 16th NOVEMBER
I managed ti find a workaround my problem. I created actor holding global variables - 2 boleans, one setting the state for adding the new elements to array, and second one to remove them. Also, I split my blueprint formulas into 2 formulas - 1 only adding points, second only removing. That way even, if the function runs twice, it will not remove or add the point when it shouldn’t do that.
However, I still don’t understand why having adding and remove options in one formula was a problem. If anyone can explain it to me - I will be very thankful