# Changing material on specific instanced static meshes when overlapped by ball

**URL:** <https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE5-0, Blueprint, question\
**Created:** [September 13, 2022, 6:15am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508 "2022-09-13T06:15:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![D\_Deng](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/d_deng/32/758117_2.png) [@D\_Deng](https://forums.unrealengine.com/u/D_Deng)\
**Post date:** [September 13, 2022, 6:15am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/1 "2022-09-13T06:15:52Z")

</div>

Hi,

I’m currently working on my first ever mobile game in unreal and have stumbled on a little road block. Does anyone know if it’s possible to change a specific instanced static meshes material when it is overlapped by a ball, without changing the material of other instanced static meshes?

And if so, how would you go about it?

The closest method I could find is this [How To Set Material Parameters On Instanced Mesh Components - Unreal Engine Tutorial - YouTube](https://www.youtube.com/watch?v=knO3R5g0s8s&ab_channel=AlexQuevillon%5BEn%5D) but it involves random float generators whereas I’m looking to change specific instances overlapped by a ball to a specific color

This is the blueprint so far

 ![Capture](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/6/196d84af79584d8918d82aa214d577bed53b7640.png)

Thanks

---

<div class="post-metadata">

**Author:** ![Polysiens](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/polysiens/32/566023_2.png) [@Polysiens](https://forums.unrealengine.com/u/Polysiens)\
**Post date:** [September 13, 2022, 7:01am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/2 "2022-09-13T07:01:43Z")

</div>

Hi,  
You should be able to do this by creating dynamic material instance of the overlapped object and changing the color parameter.

---

<div class="post-metadata">

**Author:** ![D\_Deng](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/d_deng/32/758117_2.png) [@D\_Deng](https://forums.unrealengine.com/u/D_Deng)\
**Post date:** [September 13, 2022, 9:19am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/3 "2022-09-13T09:19:19Z")

</div>

Hi, thanks for the reply.

I gave this a try a couple days ago but I think it only works with static meshes, it doesn’t seem to work with instanced static meshes.

Thanks though

---

<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:** [September 13, 2022, 10:31am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/4 "2022-09-13T10:31:56Z")

</div>

> [@D\_Deng](#):
>
> it involves random float generators whereas I’m looking to change specific instances overlapped by a ball to a specific color

Don’t use a random.

Feed it 3x `Per Instance Custom Data`, push the floats through a `Vertex Interpolator` and make a `float3`.

* * *

edit: it’s actually in the video you linked.  
edit2: here:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/b/3/7b336f72e580e2e71b8f9b57ccf587eb7b553f29.jpeg)

Use the desired RGB rather than a random.

* * *

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/4/8/748d94a2d858cda63fdfeb250279195d11605bed.png)

Is this not working for you? Also, the `dirty` flag should be set for the last instance only. Using it like this almost defeats the purpose. And that should be `Instance Count - 1`.

---

<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:** [September 13, 2022, 11:27am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/5 "2022-09-13T11:27:19Z")

</div>

> [@D\_Deng](#):
>
> change a specific instanced static meshes material when it is overlapped by a ball, without changing the material of other instanced static meshes

Is this roughly what we’re doing?

---

<div class="post-metadata">

**Author:** ![D\_Deng](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/d_deng/32/758117_2.png) [@D\_Deng](https://forums.unrealengine.com/u/D_Deng)\
**Post date:** [September 14, 2022, 12:49am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/6 "2022-09-14T00:49:01Z")

</div>

Hi,

Yes, this is exactly what I am hoping to achieve. Would the method above create this specific effect? Or is there a way better solution?

Thanks

---

<div class="post-metadata">

**Author:** ![D\_Deng](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/d_deng/32/758117_2.png) [@D\_Deng](https://forums.unrealengine.com/u/D_Deng)\
**Post date:** [September 14, 2022, 2:19am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/7 "2022-09-14T02:19:34Z")

</div>

I’ve found the answer in another forum post:

> [@Get overlapping index of Hierarchical instanced static mesh](https://forums.unrealengine.com/t/get-overlapping-index-of-hierarchical-instanced-static-mesh/461890/3):
>
> I tried breaking the hit result, and it just returns -1. Constantly line tracing would just defeat the point of using a HISM

They’ve used hierarchical static meshes but it also works for instanced static meshes. It still needs a bit of fine tuning but the effect is there.

Code for reference:

 ![Capture](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/f/1/4f1470a6a50cfa1f01b1b86adc3c1f8717836215.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:** [September 14, 2022, 5:31am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/8 "2022-09-14T05:31:52Z")

</div>

> [@D\_Deng](#):
>
> Would the method above create this specific effect? Or is there a way better solution?

Nah. Your research is spot on. It’s a good method, performant but _somewhat_ tricky to set up right.

> I’ve found the answer in another forum post:

It’s hard to tell (for me) what would be more efficient - a multibody overlap or a physical hit. I’d say the latter would be faster but it might as well be in the ballpark of negligible difference. Things can be further optimised, too.

When it comes to HISM vs ISM - which one to choose would depend on how the levels are designed and the design of the tiles. HISMs come with their own indexing baggage which can make it cumbersome. But if your tiles are complex, there is a A LOT of them, and we do not need to see all of them all the time, HISMs will be worth it.

* * *

Here’s the setup just in case:

- material:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/7/f/c7fab7617b50ed4500f408bb431a3cde8fc0a18c.jpeg)

- the ISM:

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

- the pawn interaction:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/a/7/5a7aa15059e975a6257e27c2ec9a3bb571affe35.png)

Obviously, if you do not want / need physics or want to use an overlapping volume to do more funky stuff, multibody is the way to go. Good luck with the rest!

---

<div class="post-metadata">

**Author:** ![D\_Deng](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/d_deng/32/758117_2.png) [@D\_Deng](https://forums.unrealengine.com/u/D_Deng)\
**Post date:** [September 14, 2022, 6:43am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/9 "2022-09-14T06:43:30Z")

</div>

Awesome, thanks for the extensive help and advice.

ISM with multibody overlap works perfectly for what I’m looking for (simple boxes instanced around a grid layout).

Thanks again

---

<div class="post-metadata">

**Author:** ![TwitchOgnorant1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TwitchOgnorant1](https://forums.unrealengine.com/u/TwitchOgnorant1)\
**Post date:** [March 3, 2024, 12:28am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/10 "2024-03-03T00:28:38Z")

</div>

If I add an instance to InstancedStaticMeshComponent with AddInstance(), is it possible to switch the physics on or off from each instance or can only the color be changed?

---

<div class="post-metadata">

**Author:** ![D\_Deng](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/d_deng/32/758117_2.png) [@D\_Deng](https://forums.unrealengine.com/u/D_Deng)\
**Post date:** [March 29, 2024, 3:32am UTC](https://forums.unrealengine.com/t/changing-material-on-specific-instanced-static-meshes-when-overlapped-by-ball/647508/11 "2024-03-29T03:32:48Z")

</div>

I’m personally not too sure unfortunately. You may have to create a new thread for this question. So far physics doesn’t seem to be a feature you can manipulate for instanced static meshes. I could be wrong though.
