# How can I get all index from for loop in blueprint

**URL:** <https://forums.unrealengine.com/t/how-can-i-get-all-index-from-for-loop-in-blueprint/1476069>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question, Blueprint\
**Created:** [December 5, 2023, 12:12am UTC](https://forums.unrealengine.com/t/how-can-i-get-all-index-from-for-loop-in-blueprint/1476069 "2023-12-05T00:12:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lindsay\_Han](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lindsay\_Han](https://forums.unrealengine.com/u/Lindsay_Han)\
**Post date:** [December 5, 2023, 12:12am UTC](https://forums.unrealengine.com/t/how-can-i-get-all-index-from-for-loop-in-blueprint/1476069/1 "2023-12-05T00:12:09Z")

</div>

Hi,  
I am a 3d artist completely new to blueprint, and I was trying to create a Christmas lighting system by using spline tool, my idea is let the odd number have yellow emissive material, and even number have blue one, so yellow blue yellow blue yellow blue etc. What I did is get the index from for loop, add a branch, if index %2 == 0, set yellow material, if not goes to blue. however, the for loop seems only return the last index, so material only change when the total number of element in my spline tool change. Is their anyone know where I did wrong? thanks!

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/f/e/cfe5afaa7d7f333dcd3539bc274462a2feb46086.jpeg)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/5/b0560e13df172b6d98bd0ec4a83b5608ccf207de.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 5, 2023, 12:27am UTC](https://forums.unrealengine.com/t/how-can-i-get-all-index-from-for-loop-in-blueprint/1476069/2 "2023-12-05T00:27:55Z")

</div>

> [@Lindsay\_Han](#):
>
> Is their anyone know where I did wrong?

The instances of a **single**  **I** nstanced **S** tatic **M** esh **C** omponent can only have 1 mesh and 1 material. What you’re doing will not work. Whenever you assign a material, you do not really assign it to **an** instance - you assign it to **all** instances of this one component.

You have some options:

- you could have 2 ISMc:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/5/d/95d3ad59afaf1be1490b2d08f5d396caa114f703.png)

The material can be pre-set on the component in the details panel.

- instead of ISMc, you could use as many regular Static Mesh Components as there are lights:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/e/0/2e0511b5ceb97390634f82594a09c41719785cc2.png)

- there is also a more involved technique - Custom Primitive Data

> **[UE Tip: Custom Primitive Data](https://unrealdirective.com/tips/custom-primitive-data)**
>
> Learn how you can use Custom Primitive Data to easily modify Scalar and Vector material parameters without needing Dynamic Material Instances.

> [@How to add a hit count (health points) to individual instances?](https://forums.unrealengine.com/t/how-to-add-a-hit-count-health-points-to-individual-instances/227176/2):
>
> The name of the game is Custom Primitive Data (check docs at the bottom). The material for a brick: each instance stores a float which is used to Lerp between 2 colours (to visualise hits remaining) this can (and probably should) get prettified Making a brick wall: create a bunch of instances and store their data in an int | int Map instead of an integer, you could have a struct and hold all kind of data here; perhaps this brick is worth some coins, or explodes when destroyed and …

[https://docs.unrealengine.com/5.3/en-US/storing-custom-data-in-unreal-engine-materials-per-primitive/](https://docs.unrealengine.com/5.3/en-US/storing-custom-data-in-unreal-engine-materials-per-primitive/)

This would actually allow you to achieve what you want. 1 ISM, 1 material, as many colours as you need.

---

<div class="post-metadata">

**Author:** ![Lindsay\_Han](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lindsay\_Han](https://forums.unrealengine.com/u/Lindsay_Han)\
**Post date:** [December 6, 2023, 6:11am UTC](https://forums.unrealengine.com/t/how-can-i-get-all-index-from-for-loop-in-blueprint/1476069/3 "2023-12-06T06:11:44Z")

</div>

thank you so much, I added an extra ISMc, and this solved my problem!!!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [January 5, 2024, 6:12am UTC](https://forums.unrealengine.com/t/how-can-i-get-all-index-from-for-loop-in-blueprint/1476069/4 "2024-01-05T06:12:29Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
