MouseEvents on layers rendered to texture.

Hi,

We’re upgrading our project to Unity 4 just now, and I’ve come across an issue:

We have a UI system that renders a UI object layer to a render texture, then draws that texture on OnGUI. That allows us to mix OnGUI elements with quad-based UI ones.

On Unity 3, that system worked fine. The quads (with colliders) on the UI layers that were rendered to texture responded normally to MouseEnter, MouseExit and other such events. On Unity 4, they just don’t.

I don’t know if that’s a bug, or a bug-fix (and we were the ones exploiting the bug), or if that change was by design, or even if there is a new way to do this…

So instead of jumping into a workaround fix, I thought it best to ask if anyone knows about this matter, and if there’s something we can do about it.

The workaround I have in mind would be to use Bounds.IntersectRay(Camera.ScreenPointTORay(Input.mousePosition)), or maybe a proper raycast, to explicitly check for mouseovers, then feed the events manually to the objects… Quite a good deal of work, which I’d like to avoid if at all possible.

As always, thanks in advance!

Cheers

Well, I went on writing my “manual” mouse events system here… and now it’s working again.

I’d still like to hear it if you have some other solution for this issue, but at least now you can click on things again. :slight_smile:

Cheers

I’m curious why you are using a render texture instead of just rendering via a layer and/or a separate camera directly.

Because there are actually three UI layers in use. The first one draws before the OnGUI objects, then the OnGUI call is done, then another render texture is drawn.

That allows us to cull GUI text behind quad-based UI objects, and gives us complete control over how the UI is drawn. We can also tweak the material used to draw the UI rendertextures, making it semi-transparent, for instance.

Cheers

Ah - that totally makes sense then. Was assuming GUI objects were always on top. I only asked because what I do now is almost identical except for the render texture bit and the fact that I’m building the UI out of XML data. I draw with an orthographic camera that renders quads starting at the far clip plane and moving toward the near clip plane based on ordering of elements in the XML.