Hey Guys I have a question that I haven’t been able to find the answer to -
I could really do with implementing for loops in most of my functionality, at the moment I have set up a struct because I thought that would be a good way of grouping variables that I will need multiples of for different types, however most of my for loops I set up don’t seem to work, the variables are read correctly but the set members doesn’t seem to work.
Is this a limitation of structs? I can’t find a good way of making my blueprint cleaner and taking all the duplication code out. If I can’t do the for loop here then I would have to paste this same bit of code another 5 times, and across multiple blueprints too, so then if I need to change one thing it becomes an enormous task! If I can’t use structs is there something else? I chose a struct because the PCG graph can read it which is also what I need.
Your random node is problematic since its a pure node but also SetMembers only works on a Ref not a Copy. So your find node is returning a copy. You can add the altered copy back to the Map though
Adding to what Auran13 said, setting current and last random to members in the struct is kinda odd too. If this is happening inside a function it would probably be better to use integer local vars to remember the last index. Use a default value of -1 for that, and on that second branch, check if current = the random index. Then instead of setting last random as struct member, just set the local var.
Hey thank you for the reply I really appreciate it. If you don’t mind me asking, why is a pure random node problematic?
and thank you, that makes sense, but I’m not sure adding the copy back to the map is going to work, to give a some more details I am working in construction script and I have the struct variables visible and editable in the details panel because I am using this for editor work, not runtime, so ideally would like it to affect the ref so that the changes are visible in the details panel but can also still be changed from there too. I have found a get ref array node but that doesn’t seem to get me any farther.
Hey illspiritx thank you for the reply, I did originally do it as a function with local variables and it did work but it would keep picking the same mesh multiple times again. Using the index makes more sense though, I’ve made another function and that is working, just need to be able to set my ref structs. Thanks!
It occurred to me a while ago that getting random indices during a foreach loop could result of some of them not getting used if previously used indices are being discarded.
As such, if you want to randomize an array of structs (or anything really) and ensure they all get used, you could shuffle the array then use a regular for loop with the last index pinned to array length --1. Like so:
Shuffling an array inside a struct member could get messy tho. Probably have to loop thru the struct array once to shuffle, then loop thru again to get usable results. In my case, I was just getting random icons to throw on widget grid lol.
The random node is problematic because you are calling it twice which will give two different results.
Adding back to the map will work but again your map needs to be a ref not a copy since your map is inside a structure you may need to add the whole map back to the structure. It’s kind of complicated in blueprint but really easy in c++ if you’re familiar.
Too really understand it you may need to step through breakpoints and see what’s happening