Going backwards in multigate

Hey Guys,

I had a quick question and i could really use some help. I have a actor BP with a multigate that changes material of an object between 5 different materials when I press a button.through the set material node.
I can loop through them one by one, but I cannot go backwards, i.e. i can go from material 1 to 2 and 2 to 3 and 3 to 4 and so on. I want to be able to also go from 1 to 2, 2 to 3, 3 to 2, 2 to 1. Basically the ability to go back and forth within this multigate.

Any one has any ideas on how to do that? Any help would be much appreciated.

Kabir,

Not for sure how you have it coded at this point (multigate could mean a lot of things). But the simpliest way to do what you wish, is to have the N number of materials in an array of Materials, and then have a “current index” for the index into the material array.

So when you press button to advance forward, it just takes the current index value into the material array, and increments it to the next index, if the index incremented too, is greater than the last index, wrap back to zero, and this will advance.

if you set up another button, to go backwards in the array, it would take the current index value and decrement it, checking that it is less than zero, and if less than zero, then set it to the last index for the array, and this will go backward for you.

No matter which button is pressed, as you will be checking the current index value for it to be invalid, the code will “wrap” from either the end of the array to the start, or from beggining of the array to the end, and the code you have already set up, to actually set the material will not have to change. It will just take the “current index” value for the array, and set the material for it, and be done.

Hope this helps.

Inc.

if you increment the int, you cannot go backwards, and the bounds checking will still need to be done, as one is messing around with the index into an array. The “switch” doesn’t reduce the complexity of the “output” desired by the poster. The ability to determine when outside the bounds of the array is still needed, and whether to decrement or increment the array index is still needed.

Instead use a “switch on int” and increase the int by one every time. That way you can go backwards and forward or even skip. Same idea as the other post just more easier to do.

Obviously you gonna have two buttons one to increase the int and one to decrease the int. That’s why I said same idea as the other post. But simpler because he already understands the mulitgate and is very similar to that idea.

obviously sticking with a “gate solution” (even though a switch is not a “gate” in the historical sense), is not the best solution in terms of maintainability, etc.

Here’s a rough solution, no switch statement/gate needed, and the node structure maintains itself, just add or remove materials as needed.

Inc.