Changing material on specific instanced static meshes when overlapped by ball

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 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

Thanks

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

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

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:

Use the desired RGB rather than a random.


image

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.

Is this roughly what we’re doing?

1 Like

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

I’ve found the answer in another forum post:

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:

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:

  • the ISM:

  • the pawn interaction:

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!

2 Likes

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

1 Like

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?

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.