render an arbitrary mesh as wireframe

So, just wondering the easiest way render only a particular mesh in game as wireframe. The most obvious idea I had was:

  • make a wireframe material
  • WireFrameMode - ON: swap all of the mesh’s material to the wireframe material
  • WireFrameMode - OFF: swap all of the mesh’s textures back to previous material

I notice that all materials have a default “Wireframe” checkbox, but if I am not mistaken, that would require instancing every single material? Because only a particular mesh should render as wireframe, not all meshes using that material.

Is there an easier way built into the engine? I’ve seen some code in the source for RenderProxies. Is that a better route?

I forget if wireframe is something you can set on a dynamic material instance, but if it is:

Set up a blueprint to replace your existing actor. Add a staticmesh object (or whatever kind of mesh you’re using).

In the blueprint add a MaterialInstanceReference variable. In the construction script of your actor get the material assigned to your staticmesh object and create a dynamic material instance using it. Replace the mesh material with that dynamic material instance and populate your variable with it. This will give you a material instance per actor.

The pictured example is a bit different from what I mean - “Fur Material” is a property on the actor used to override the actual mesh material. You’d use Fur Material like your wireframe material and add another variable to save the original mesh material.

Now you can adjust that specific material instance’s properties and shading options at runtime using the actor and its MaterialInstanceReference variable. Keep in mind you won’t be able to do anything in a game that causes shader re-compilation though.

Edit: That’s not going to work, wireframe is not a dynamic runtime option for materials. I’ll leave the above guide there though as it’s useful in other ways.

What you can do is make a wireframe material and switch the mesh material to it at runtime. You can use the above as a guide for that too, just instead of modifying the material reference’s properties, make a function in the blueprint to set an entirely new material and then a function for switching back to the material you stored at construction time. If you want to modify the wireframe material to get a custom colour, for instance, you can do it in the way I explained above and set some material properties.