Raycast collision problem after changing transform.localScale [solved]

I have laid a Quad over top of my scene which I’m using as a grid, and I want to find out what I’m pointing at. The problem seems to be that if I resize the Quad, the Raycast doesn’t hit it anymore. If I leave the size alone everything works fine.

    public void LinkMap (Map map)
    {
        this.map = map;
        // This line is the problem
        Grid.transform.localScale = new Vector3 (map.width, map.height, 0);
        Grid.GetComponent<Renderer> ().material.mainTextureScale = new Vector2 (map.width, map.height);
        Grid.gameObject.SetActive (true);
    }
    public void PerformRaycast ()
    {
        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        RaycastHit hitInfo;
       
        if (Physics.Raycast (ray, out hitInfo)) {
            // This always returns stuff under my grid
            Debug.Log (hitInfo.transform.tag);
            if (hitInfo.transform.CompareTag ("MapOverlayGrid")) {
                // This is the tag assigned to my Grid
                // Always works if I don't resize the Grid in LinkMap
                Debug.Log(hitInfo.point.ToString ());
            }
        }
    }

In my editor I can clearly see that resizing works as expected and the object is as I expect it to be. It’s above the scene. Is there a known workaround or is there something I should know that I’m not doing after resizing?

Update:

Ohhhhhhh that was causing me endless torment.

Solution it needs 1f rather than 0

Grid.transform.localScale = new Vector3 (map.width, map.height, 1f);
2 Likes