Applying materials to the new UI elements (4.6)

Hello everyone,

I’ve been working with the new UI system and got myself a problem.
In this specific project (standalone), whenever the user clicks any two spots in the screen, a ruler appears and the distance between points is given. The first version of this in game tool was made with procedural meshes, 3dText and a few other components. Now we think it’s about time to migrate to the new UI.

When using a Canvas element with Render Mode set to World Space, the ruler itself is an image element and the measurement is presented as a text element, both as child objects to the canvas. After getting information from the mouse clicks, the canvas is positioned via script (so far, so good).

However, when there’s an obstacle between the points, part of the ruler gets occluded. With a custom ShaderLabs shader applied to a material, it was possible to have a MeshRenderer always visible, but applying the material to UI elements doesn’t seem to work.

Any ideas as to how can we keep a WorldSpace canvas always visible without needing a second camera to render only it’s layer with clear flags “depth only”? How are shaders in materials applied to the new UI elements?

Thanks in advance

Check out DanSuperGP’s answer here, and vote it up because it works like a charm: