Is it possible to set visibility of a single instance of an instanced static mesh component?

So I currently have an angled “top down” game where occasionally, I might have an object or two in between the camera and the player. Seeing as how this might be problematic sometimes, I did something similar to this to set individual components visibility when they block the view.
However, for performance reasons, I’m using “instanced static meshes” and when a single component’s visibility is set, all instanced mesh’s visibilty are also set.

Is there a way to set the visibility of a single instance of an instanced static mesh component?

1 Like

Instanced Static Meshes are basically one single big mesh so unfortunately no. What I personally did was create a material that turns transparent (Masked material + DitherTemporalAA) when it “intersects” the camera vector.

Could you elaborate a little for me? Would it then be possible to set the material of a single instance in an instanced mesh? I’ve considered this idea, but I couldn’t figure it out.

The material is one and the same, but since it takes the camera position and direction to create a “cylinder” mask, only the instances actually close to the camera would be affected. Thing is though it’s done PER-PIXEL, not PER-INSTANCE. Ends up looking good enough though.

That sounds amazing. I’ve never heard of such a thing. Do you have any link where I can read up on how to do this myself or watch a tutorial on how to do this? I’d google it myself, but I’m not sure what to even search for, considering I’ve never heard of this before.

Unfortunately it’s all home-made and not public. :frowning: But it’s really not difficult to do. Look up some math on point-to-line distance, where your point is your Absolute World Location and the line is the camera vector. If the distance is below a certain threshold, you set opacity mask accordingly.

Not sure if this is still an issue. But this is now possible. Take a look at my blueprint below to check it out. You can also set a different mesh all together in a place in the mesh. I set LoctionX to 0 to start with and PannelSize I have set at 245 but that can be configured to match a mesh of your choosing.

This is an old one, but just set the scale of that instance to zero. easiest way to make it not render without needing to change materials and what not.

That’s what I tried, but unfortunately it’s not working how I hoped it would work.

As you have it set up, you’ve created multiple “instancedStaticMeshComponents” each with only one attached instance.
(and there’s a limit of the # of instances you can have, something like 10 - check the output log)

As far as I understand, every instance shares the properties of the render component. So you need one instanced component for each group of similar looking meshes.

The transform seems to work on each instance, so perhaps the “scale to 0” approach might work to make one instance invisible

nice ideal

this is a really neat idea and something I’m going to use, thanks!

Very good tip, thanks a million man, you saved me a lot of code!

Setting the scale to 0 is great, but I found that an unintended side effect was that the instance’s rotation was lost in the process somehow. (Example: Setting rotation to 0, then back to 1, caused the rotation to be reset to default. This does not happen when I set the scale to 0.1 instead.) The solution is to store the rotation somewhere before you set the scale to 0.

See here for details on how this is intended: https://answers.unrealengine.com/questions/158576/update-instance-transform-sets-rotation-to-000.html