SetMaterial causing flashing

I am using custom shading nodes to toggle between different shading effects on my meshes. When I want to swap effects, I just use SetMaterial to change the material I’m rendering. This causes a flickering effect while seems to go back and forth between different materials. I am rendering all of this in VR with dynamic lighting. Is there a better way to swap materials during runtime?