Search Unity

What's wrong with RectTransformUtility.RectangleContainsScreenPoint Camera argument?

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by shoo, May 27, 2015.

  1. shoo

    shoo

    Joined:
    Nov 19, 2012
    Posts:
    60
    Hello! I am trying to use RectTransformUtility.RectangleContainsScreenPoint but I have weird trouble with camera. I just have empty project with new scene which have camera on it, also it have UI panel and canvas, so it should be not any conflicts. But finnaly I have this problem Debug.Log(RectTransformUtility.RectangleContainsScreenPoint doesnt work if CAM parameter will be not null. I mean:

    RectTransformUtility.RectangleContainsScreenPoint (rect, pos, Camera.main) - doesnt work

    public Camera cam;
    RectTransformUtility.RectangleContainsScreenPoint (rect, pos, cam) - doesnt work too

    RectTransformUtility.RectangleContainsScreenPoint (rect, pos, NULL) - WORKS GOOD

    So I have no idea what I am doing/understanding wrong. Is it a bugg?
     
  2. shoo

    shoo

    Joined:
    Nov 19, 2012
    Posts:
    60
    It is sad.
     
  3. Mark-Currie

    Mark-Currie

    Joined:
    Sep 6, 2012
    Posts:
    44
    I'm seeing the same thing. Thanks for the suggestion of using null for the cam parameter.
     
  4. hmortensen2907

    hmortensen2907

    Joined:
    Aug 1, 2012
    Posts:
    11
    Know this is old, but I just hit the same "challenge" ;)

    I found, that if your canvas is set to "screen space - overlay", RectangleContainsScreenPoint won't work with a camera parameter! Probably because there are no camera defined for the canvas.

    If you use "screen space - Camera" or "world Space" where you do define a camera for the canvas, everything seems to works :)
     
    Leniaal, shoo, IgorAherne and 3 others like this.
  5. AshleyHsu1

    AshleyHsu1

    Joined:
    Jun 3, 2019
    Posts:
    1
    You are a life saver dude.
     
  6. redagrandrei

    redagrandrei

    Joined:
    Sep 3, 2017
    Posts:
    34
    Assume you could leave just - RectTransformUtility.RectangleContainsScreenPoint (rect, pos)
    Third parameter is just optional and usually not needed.
     
  7. therocknwork

    therocknwork

    Joined:
    Apr 20, 2015
    Posts:
    3
    You need to provide your UI Camera as third parameter to RectTransformUtility.RectangleContainsScreenPoint to make it work correct