Why is spawning random actor and getting array eement in macro returning conflicting info?

I have a macro set up that chooses a random actor from an array and outputs it. The same macro also get the array index and outputs it. When I run the game it sucessfully picks a random actor and spawns it, however the debuging print string I have attached to the array index output shows a diffrent value than is should be. Gun1 is at array index 0, Gun2 is index 1 and BatteryUnit is index 2. further more i have a check to see if the battery was chosen and to set the power level accordingly. this also has an error because it seems to randomly assign a true or false to the branch node thus ramdomly assigning a power level of 100 or 300.

thanks for the help!

Replace length with last index. length will give you a length of 1 if you have an item at index 0. Last index will give you index zero if you have an item at index 0.

still not working, I also swapped random integer with randon integer in range and no change. and i get get the worng battery value randomly. it should only be at 300 if the battery is atttached. but it is getting a value of 300 when guns are attached. Image below(conflicting2) shows gun 2 being spawned and a array index of 0( which is gun 1 location in the array.) And the image(conflicting4) shows gun 1 and array index 1 which is gun 2’s location. These are not constants teh array element changes every time, sometimes they are shown is array element 2 and some times they are in the correct array element.

286957-conflicting4.png

286955-conflicting2.png

Sorry, I should have noticed this before; its also because whenever you call a ‘random int’ you will get a new random int. Even if youre using the same node it will be different. You will want to create a local variable that holds the random int.

a local variable inside the macro or inside the Actor BP?
Edit: turns out you cant make variables inside macros, I tried moving it all to the actor BP but I’m still getting the same results.

I figured it out with your help. Attached is an image of the BP if anyone in th future needs help with the same issue.

Thank you so much guys! This was extremely helpful as I had the exact same random conflict issue. I would like to add some explanation notes for any absolute beginners like me reading this in the future:

  • The node combo of “Last Index” and “Random Integer in Range” can be replaced with “Random Array Item” but please note the pins “Out Item” and “Out Index” are not linked for this alternative node. So only use one of them, preferably Out Index, towards the Set (Attachment Array Index) node in Moist_Plasma’s image above.

  • The Set node itself can be made by first making a variable under the Event Graph section, using the variable command on the left side or “My Blueprint” tab. Click the plus sign to add a new variable and specify the integer type. Then drag it in and specify to set (not get).

Hope this helps clarify things and save some time for you awesome future devs.