OnMouseDown only occurring once - SOLVED

Steps to repro:
Create a new script
Add an OnMouseDown() method that prints a Debug message.
Add script to object in scene.
Play.
Click on your object. Result: Message appears.
Click again. Result: No message appears.

Here’s an example:

using UnityEngine;
public class SelectableOb : MonoBehaviour 
{
	void OnMouseDown()
	{
		Debug.Log("Clicked on " + this.gameObject.name);
	}
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

It seemed to me that the single click thing was almost like the object was behaving as a static. Although that’s probably not technically the case, it gave me the idea to try adding an instance member.

e.g.

using UnityEngine;
public class SelectableOb : MonoBehaviour 
{
	int dummyCount = 0;
	void OnMouseDown()
	{
		dummyCount++;
		Debug.Log("Clicked on " + this.gameObject.name + " " + dummyCount);
	}
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

And it fixed it. Clicking multiple times works.

I’ll probably just sound dumb if I guess why, but anyway, I thought someone might benefit from this info.

[Update] The event occurred originally, but was masked by the Console’s Collapse, since the text did not change.

In your console, disable the Colapse option.

1 Like

Good thing I didn’t guess why :slight_smile:

Thanks a lot. It helped.!