MouseEnter Failing

Hi, I’m creating a grid of planes with a script attached to them that turns them black when the mouse passes over them. Here is the entirety of that script.

function OnMouseEnter () {
transform.renderer.material.color =;

Every plane has a collider and no plane is overlapping another.

The problem is that if you swipe your mouse across at even a slightly fast speed, some of the planes are not triggered i.e. they do not turn black. I know for certain that the mouse has gone over them, they just don’t trigger. The plane size is 0.1X, 0.1Y, 0.1Z (but I’ve tried it with cubes that are 1,1,1 and it does the same thing).

I either need a new method for using the mouse to interact with objects that has a 100% hit rate, or a fix for OnMouseEnter(), because it is not hitting if you move the mouse too fast. Keep in mind I’m ideally dealing with a large number of planes (in the 1000’s) here but the bug happens on small amount too (40).

I’ll post my code for the spawning the planes in a grid, although I’m already certain they are laid properly, since I’ve manually done the counting.

var ScreenSize : double;
var MaxLength : double;
var BlankPixel : GameObject;
var Value : double = 0;
var X : double = 0;
var Y : double = 0;
function Start () 
	X = -MaxLength/2;
	Y = -MaxLength/2;
		while(Value < ScreenSize)
			clone = Instantiate(BlankPixel,Vector3(X,Y,0),Quaternion.identity);
			clone.transform.eulerAngles = Vector3(270, 0, 0);
			Value += 1;
			X += 1;
			print("(" + X + "," + Y + ")");
			if(Value%MaxLength == 0)
				Y += 1;
				X = -MaxLength/2;

My next step is going to be testing it with GUITextures (which is probably a better idea for performance anyway), I’ll let you know when I finish setting up the positioning code. However, I don’t know why OnMouseEnter would work for them when it doesn’t work for a plane.

Anyway, thanks in advance for the help.

EDIT: Have checked with GUITextures and same thing occurs. Anyone have any ideas, this is a real roadblock for my project.

OnMouseEnter can only work as fast as the framerate. If you move the mouse fast enough, then it’s quite probable that during one frame the mouse is over a particular object, and during the next, it’s over an object some distance away, with no way of knowing that you wanted it to affect the objects in between. You can write your own code to do the interpolation if the mouse has moved a sufficient distance between frames. I wouldn’t recommend using separate objects though, especially not thousands (which will kill the framerate). Use one object, and instead of OnMouseEnter, use raycasts and RaycastHit.textureCoord (and turn off bilinear filtering for the texture so you get clean edges). Edit: and if you do this, then you can use this script to do the interpolation.