Search Unity

Graphic Raycaster used to have a priority?

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by rakkarage, Dec 4, 2014.

  1. hansadler

    hansadler

    Joined:
    May 12, 2014
    Posts:
    41
    I have this same problem. I have two canvases in world space. The second canvas has a button that cannot be clicked when running under 4.6.1. It was working in 4.6.0.

    I have installed 4.6.1p2, but it's still not working. I tried playing with the setting in both canvases and changing the z order and the order in the layer, but nothing seems to change. Am I missing something? What do I need to do to make this work?
     
  2. djdavidrevolution

    djdavidrevolution

    Joined:
    Nov 16, 2014
    Posts:
    6
    I've just finished tried with the branch patch but it didn't work. Neither
    or
    worked for me so I suppose that I will wait for version 4.6.2 while I'm still checking this thread.
    Thanks everybody for your help! ;)
     
  3. andrewhilvers

    andrewhilvers

    Joined:
    Jan 21, 2015
    Posts:
    1
    This worked perfectly for me, create the c# file named WorldRaycaster.cs . Place the code below in it. Replace your graphics raycaster component with this file and BAM it works haha

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class WorldRaycaster : GraphicRaycaster
    6. {
    7.     public override int sortOrderPriority
    8.     {
    9.         get
    10.         {
    11.             if(GetComponent<Canvas>().renderMode == RenderMode.ScreenSpaceOverlay
    12.                || GetComponent<Canvas>().renderMode == RenderMode.ScreenSpaceCamera)
    13.             {
    14.                 return GetComponent<Canvas>().sortingOrder;
    15.             }
    16.  
    17.             return base.sortOrderPriority;
    18.         }
    19.     }
    20. }
    I will just use this till Unity officially fixes it I guess
     
  4. Keldrin

    Keldrin

    Joined:
    May 27, 2013
    Posts:
    9
    I have a similar situation. One canvas (screen space - camera) is part of the scene from the start (controls the core UI screen flow), then I have dialogs that are instantiated from prefabs and have their own canvas, also screen space - camera.

    Originally they were on the same sorting layer with the core canvas at 100 sort order and dialogs at 200. I wanted to dim the background and let touches outside the dialog frame dismiss the dialog so I created a full-screen, mostly transparent button behind the dialog panel as part of the dialog's canvas.

    Oddly the controls directly on the dialog (the "OK" button for example) worked, but the fullscreen button wouldn't receive a click. Further, buttons on the core canvas below it were responding to mouseovers and clicks, even with Block Objects set to 'All' on the dialog canvas.

    I attempted to apply the WorldRaycaster workaround above, and it worked; but only if I ultimately put the dialogs on another sortingLayer *AND* it had to have a lower sort order than the core canvas, even though they were on totally different sortingLayers, which I imagine shouldn't have any effect if things were working properly.

    Phil, I'm on 4.6.1p5; is any of your branch stuff in this patch release? If so, I guess I have another use-case not covered. If not, I'd like to try yours to see if it fixes my specific problem.
     
  5. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    Not fixed in 4.6.2.
     
  6. Noah Dyer

    Noah Dyer

    Joined:
    Dec 15, 2014
    Posts:
    3
    Hi @phil-Unity ,

    Thanks for monitoring this thread. I have followed the directions with your bitbucket update, but I'm still having the issue where canvases and their children are not processed according to their order in the hierarchy. I've created a sample project and attached it here. Please let me know if you get different behavior with your current version, and if not, how I might fix it.
     

    Attached Files:

  7. Assassinbeast

    Assassinbeast

    Joined:
    Nov 4, 2013
    Posts:
    31
    So, i read that it is fixed... but at this moment, i have version 4.6.1p5 and it seems to still not work. I have the same problem exactly like Rakkarage wrote at the beginning of this post from 2 months ago =(
     
  8. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,159
    Yea there were a bunch of delays getting fixes into release (christmas, IL2CPP, ect) From what i can see during my latest push to the release branch is that alot of my fixes that i though were to get into a early release never were acctually released. Try 4.6.2p1 when it comes out.
     
  9. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,159
    So took a very quick look. at your project and the issue for you is the system is confused as to whats on top. You have a bunch of root canvas's all on the same layer all at the same depth. In this case the system has no idea whats on top of what so it "guesses". simply just changing the order to its explicit will resolve your issue.
     
  10. Noah Dyer

    Noah Dyer

    Joined:
    Dec 15, 2014
    Posts:
    3
    Hi @phil-Unity,

    I assume you are not talking about the hierarchy order, and I also assume you are not talking about z, since the project illustrates that both those approaches don't work. What order should I make explicit?
     
  11. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,159
    The canvas order
     
  12. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,159
    4.6.2p1 is out give it a try.
     
    m3ndi3 and Noah Dyer like this.
  13. Noah Dyer

    Noah Dyer

    Joined:
    Dec 15, 2014
    Posts:
    3
    4.6.2p1 fixed my issues. Thanks!
     
  14. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,634
    Great to hear this issue is resolved @phil-Unity Fantastic work! :D
     
    Noah Dyer likes this.
  15. Keldrin

    Keldrin

    Joined:
    May 27, 2013
    Posts:
    9
    @phil-Unity I still see an issue with two canvases in the scene when they're on different Sorting Layers.

    My sorting layers are implemented as:
    background
    Default
    gameplay
    ui
    dialogs

    I have my main UI (Screen Space - Camera) on sorting layer "ui" at Order in Layer set at 100. I instantiate dialog prefabs with their own canvas (still Screen Space - Camera) on Sorting Layer "dialogs", Order in Layer set at 1.

    The raycasts hit the main UI elements first despite the dialogs being closer to the camera. If I switch the Sorting Layer on dialog's Canvas to the "ui" and bump the Order in Layer to 101, then the dialog gets the raycasts first. I also tried just setting the dialog to order 101 without changing the Sorting Layer but that didn't work.
     
  16. Keldrin

    Keldrin

    Joined:
    May 27, 2013
    Posts:
    9
    Looking into the UI source and doing some debugging, I think there's an issue with the raycaster's interpretation of the Sorting Layer. BTW, this is on 5.0.0RC3.

    I dumped the contents of RaycastResult several times and found that the order appears bugged based on the order of the Sorting Layer's *uniqueId* as an int, not the actual sorting layer order in the layer list. Here's what I found:

    My layers:
    background (ID: 3395587757)
    Default (ID: 0)
    gameplay (ID: 2003661311)
    ui (ID: 1293112713)
    dialogs (ID: 2711576737)

    When I dump RaycastResult when my dialog is on the "dialogs" layer, the ID returned by RaycastResult, at least as output to the log, is -1583390559 I assume since it's signed. In this configuration the dialog gets the raycast last, behidn the normal UI which is on the "ui" layer. As I said before, if I move the dialog canvas to the "ui" layer (and put the order-in-layer high enough) it works as expected.

    The odd part (and the basis of my guess as to what's wrong), is if I move the dialog canvas to the "gameplay" layer which is behind the "ui" layer, it disappears visually (as it should), but the RaycastResult returns it *first*, and the dialog receives the click. I'll file a bug on this now, but figured you'd want to know since you've been in the code recently.
     
  17. Keldrin

    Keldrin

    Joined:
    May 27, 2013
    Posts:
    9
    Pretty much confirmed: If I go into Unity's Debug mode and change the UniqueID of the "dialogs" Sorting Layer to 2011576737 (which doesn't flip negative since it's below the signed int threshold) then the dialog box starts receiving the raycast first as expected.
     
  18. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,159
    Hmm well thats just not cool :(. I'll definitely be taking a look at this as thats just wrong.
     
  19. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,159
    Well thats been fixed look for it "soon"
     
  20. Keldrin

    Keldrin

    Joined:
    May 27, 2013
    Posts:
    9
    Awesome, thanks Phil! BTW, I had filed a bug, case #675139 so you can mark it resolved.
     
  21. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,634
    Great news @phil-Unity there have been a fair few reports of the CanvasGroup not blocking raycasting in to a 3D scene.
     
  22. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    299
    So I have the same issue with some of my Sorting Layers. I assume it's not a good idea to fiddle the the sorting layer IDs though?
     
  23. drHogan

    drHogan

    Joined:
    Sep 26, 2012
    Posts:
    166
  24. gilianp

    gilianp

    Joined:
    Mar 24, 2014
    Posts:
    4
    I also have this problem, I not able manage clicks on different canvas. Only if them are with same sortingLayer, then I can control them changing layerOrder, but this is not good for my logic.
     
  25. RafaelRato

    RafaelRato

    Joined:
    May 5, 2015
    Posts:
    1
    This also happens to me, but instead of it being a button on top of an other i have a canvas on top of my buttons, is there a way to fix it or do i also have to wait for the patch?
     
unityunity