How can i Avoid Doing this 24 times? Setting One Array Element at the index from other array at same index

Noob in distress

Hello,
Just trying to look for a way to avoid doing this 24 times (both array have 24 elements)
I want to get the Sprite Assets from ‘Sprite Array for Set’ at the index and assign it to the ‘Sprite BP Asset Array’ at the same index as the first one.

Example -

Element at index 0 in SpriteBPArray will get the element (sprite) of SpriteArrayforSet at index 0 and set the source sprite of that asset with the one in the array at index.

Element at index 1 in SpriteBPArray will get the element (sprite) of SpriteArrayforSet at index 1 and set the source sprite of that asset with the one in the array at index.

and so on for all 24 elements.

I’m doing this in a function as i have to do this several times (10 times) in the blueprint.

Hi Ninjin, Thanks for the reply,
I did something like this following your instruction.

Now the problem is it’s working fine here,
(Executing everything through custom event, and calling custom event through a UMG button).

But if i create the code in a function (from first foreachloop node to last print string), it only does the first array index.
(Calling the function from the same UMG button. Removed the custom event)

And also i want to change sprites (while i’m playing the game on button click) but it isn’t happening. The sprite changes in editor when I close the PIE Window and remains for the next time i run the game.

Got it.

It works great :slight_smile:

but the sprites still doesn’t change while i’m playing?
(I Click on the UMG button while in PIE Window. The print log works fine and setting every sprite as the execution, but the PIE editor doesn’t reflect the changes in game, but after i close the PIE Window, the sprites are changed.)

and i have to do it several (which will be predefined) times in the game.

ok I’ll try what you suggested, and will make another post about it separately.

Thinking now, I should have written index number instead of index to make myself more clearer. Got lost in translation.

And thank you for all the help :slight_smile:

Use a ForEachLoop Node. Take the ArrayElement and plug it into Target of SetSprite. Then you take the array index and use get on your other array and plug that into the same SetSprite Node. Report back if you got any issues following the instructions! <3

Delete the 2nd ForEachLoop and use a Get Node instead. You can totally use the function from the first picture. Is the bell ringing now? <3

It seems like you can’t just change Sprites dynamically in runtime like that. The workaround looks interesting, you just need to change the mobility settings to stationary and back to moveable. Probably need to find a better solution for it, but for now this should work.

Also, if this workaround is not working out, it would be great if you can open another question and explain your situation with more details, because your initial answer is how to get access to multiple arrays in the same for loop in blueprints (great name, I know: D) and perfectly answered by yourself with that screenshot of yours, so introducing new issues on the same answer is just bloating things up :stuck_out_tongue_winking_eye: