Strange problem with mesh collider

Hi.

I got a strange problem with some of my buttons where I don’t exactly know where to start searching for a solution.
In my project I use several buttons which I instanciate once. The buttons have the hirarchy:

Button gameObject with mesh + texture (without collider)
|
→ gameObject with same mesh and mesh collider
|
→ gameObject for icon with texture (without collider)

Most of these buttons work as intended, but some buttons have a strange problem where the collider doesn’t react on the raycasts in some areas. It seems like there are “holes” in the mesh collider or that something overlaps the mesh collider.

When I move over the button, I can see in the debug view of the inspector that the collider of the button is hit, but when I move the mouse over these holes. There is no other collider shown in the debug info, so there is not another collider which overlaps the button collider.

Has anyone similar experiences or some hints what could cause this problem?

I attached a picture to explain a little bit more what the problem is.

Thx for help!

113397--4360--$problem_347.jpg

Well I’m still pretty new to unity, but maybe I can help. I have worked on a 3d HUD, using meshes and such for buttons. It looks like your button is a simple box, could you not just add a regular box collider to it instead of a mesh collider? If the box collider is behind something you should be able to bring it forward so it stays in front. Using simple box collider could clear up strange anomalies you might be getting from a full on mesh collider. Additionally, you mentioned using a raycast which for GUI is probably not necessary. You can overload the functions OnMouseEnter, OnMouseExit, etc in scripts attached to the button. These functions go off when the event occurs on a GUIElement or a Collider, a simple example below I’ve done in c#, should just change the colors of the button when you mouse over and out. Just attach it to a cube, or try it on your button and don’t forget to change the MouseOverColor property.

using UnityEngine;
using System.Collections;

public class ActionButton : MonoBehaviour
{
	public Color MouseOverColor = Color.white;
	
	private Color OriginalColor;
	
	void Start ()
	{
		OriginalColor = renderer.material.color;
	}
	
	void Update()
	{}

	void OnMouseEnter()
	{
		// Bug fix where these events may get called at design time - lol.
		if (!Application.isPlaying) 
		   return;

		renderer.material.color = MouseOverColor;
	}

	void OnMouseExit()
	{
		// Bug fix where these events may get called at design time - lol.
		if (!Application.isPlaying) 
		   return;

		renderer.material.color = OriginalColor;
	}
}

Thank you for your reply.

I attached a script to the button to change the mouse over/click/pressed state texture, I forgot to mention that :wink:

I tried your proposal with the box collider, but same problem here. The collider doesn’t response in some small areas of the button.

More strange is the fact that this occurs not when I load my scene the first time. Then I scale and fade the button out and in for animation purposes. After that there are the “holes” in the button.
Maybe I have to refresh the mesh of the collider?

Are there any other object(s) somewhat in-front of the button?

Seems like it’s getting block or something just a guess

Ray

Yes, the gameobject with the icon texture is in front of the gameobject with the collider (desc. in the first post).
As this gameobject doesn’t have a collider it shouldn’t block the raycast, that is what I hope :wink:

There is nothing else in front of the button. Could a plane with a texture, but without a collider block the raycast to a unterlying gameobject? It shouldn’t but maybe a bug?