Search Unity

A naive raycast problem solution for people who are tired enough.

Discussion in 'UGUI & TextMesh Pro' started by jhkimblue, Sep 30, 2015.

  1. jhkimblue

    jhkimblue

    Joined:
    Mar 27, 2015
    Posts:
    14
    *Notice. it may not fit with you're case. i'm not a unity guy who has responsible for write right code for everyone. but you could get a idea from my solution. :) And sorry about my poor grammar, I'm not a native. :p

    First of all, I'm tired with waiting a patch to solve this. This raycaster problem is existed since the first version of unity 5 until now. And It was too painful to hard-code workarounds case-by-case. So i finally open the ugui project which is open project at bitbucket. I changed just a line of code, and it worked nicely.

    0. I used 5.2.0 version for this solution. go get a project at here
    https://bitbucket.org/Unity-Technologies/ui/downloads

    1. GraphicRaycaster.cs Line 181.
    Code (csharp):
    1.  
    2. sortingLayer =  canvas.cachedSortingLayerValue,
    3.  
    Change this code to
    Code (csharp):
    1.  
    2. sortingLayer =  canvas.sortingLayerID,
    3.  
    this.

    And you're done. Just build dlls and put its in a installation folder as instructed here.
    A line of code change will resolve most of raycaster issue.
    https://bitbucket.org/Unity-Technologies/ui/overview

    ps1. in my view, the evil of root for this problem is EventSystem.RaycastComparer() and Raycasters. if you face another raycast problems, take a look those classes.
    ps2. if you're facing a compile problem at editor when you try to bulid, restart your editor it'd resolve many issues. :)
     
    Last edited: Sep 30, 2015
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    according to my repo tracking this exact fix was done in 5.2.1p1
     
  3. jhkimblue

    jhkimblue

    Joined:
    Mar 27, 2015
    Posts:
    14
    thanks for your info. and please make a good patch note next time since i couldn't find any note about it. :)
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Wasn't me who added it so not sure why it wasn't included in the patch notes. :(
     
  5. Peez-Machine

    Peez-Machine

    Joined:
    Jul 30, 2013
    Posts:
    27
    Which issue exactly is this about? I'm in 5.2.1.f1 and still having issues with raycasters when used with world-space canvases and perspective cameras. I submitted a bug report with code to fix the issue (raycasters using Raycast instead of GetRayIntersection) a few weeks ago, but it was never turned into an Issue.
     
  6. jhkimblue

    jhkimblue

    Joined:
    Mar 27, 2015
    Posts:
    14
    it's about when you use multi canvases with multi sorting layers.
     
  7. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    5.1.1f1 is older than 5.2.1p1.

    RE Patch notes: It looks like they didn't get copied from our patch note staging area to our public release notes. I've notified someone about this.