Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Graphics.DrawMesh and 2D sorting layers ??

Discussion in '2D' started by kauaiBlake, Jan 27, 2014.

  1. kauaiBlake

    kauaiBlake

    Joined:
    Feb 28, 2013
    Posts:
    34
    Hi there,

    We are making a 2D game, and heavily using 2D sorting layers. Everything is fine on that end, but one part of our technology base is some custom code that uses Graphics.DrawMesh, as listed here in the API... http://docs.unity3d.com/Documentation/ScriptReference/Graphics.DrawMesh.html

    Now the Graphics.DrawMesh call does have a layer argument, but I believe that is not refering to sorting layers, but instead the old layer system. Its hard to check though, as the link for the layer argument is a dead link.

    Anyway, if I have other game objects, I can call this kind of code to make them work with sorting layers....
    _renderer = gameObject.GetComponent<SkinnedMeshRenderer>();
    _renderer.sortingLayerName = sortingLayerName;

    I do not see anyway to get a renderer object from a Graphics.DrawMesh call. Does anyone know a way to get the call to Graphics.DrawMesh obey sorting layers to integrate into our 2D game scene?

    Thanks,
    Blake
     
    Eluem likes this.
  2. pixelsplit

    pixelsplit

    Joined:
    Sep 16, 2013
    Posts:
    124
    I think this isn't possible currently.

    But you could use more than one camera.
    For example use Camera 1 to draw 2D stuff from layer 0-10, Camera 2 for your mesh, Camera 3 for 2D Stuff from Layer 10 upwards.
    Then you set the rendering paths of these cameras and it should work.
     
    Last edited: Jan 29, 2014
  3. kauaiBlake

    kauaiBlake

    Joined:
    Feb 28, 2013
    Posts:
    34
    Yeah that came up in our discussions , but we were really hoping there might be a way to do it without multiple cameras. Would be nice to hear drom a Unity dev , to know if they have considered this.
     
    Eluem likes this.
  4. Eluem

    Eluem

    Joined:
    Apr 13, 2013
    Posts:
    43
    I'm surprised that it's been 2 years and there's been no response to this yet. It seems like quite a major issue that would be fairly easy to resolve, if I understand how DrawMesh works correctly...

    I need this feature to make use of the far more efficient version of XWeaponTrail that shallway released which uses it. I could manually convert all the work back to using a mesh object... but this seems unnecessary...
     
  5. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    159
    it still has not been addressed, as far as i can tell. DrawMesh appears to be drawn as sorting layer 0, no matter what you do. You can use command buffers to inject at various points in the render pipeline, but that is horrendously slow on platforms that do not support instanced drawmesh calls. (1000 drawMesh calls every frame is ok vs rebuilding a command buffer with 1000 drawMesh calls every frame = crap framerate).
     
  6. Thrawn75

    Thrawn75

    Joined:
    Nov 16, 2014
    Posts:
    2,234
    Now that Unity is adding new features to Mesh API in 2019.3, it would be great to see that option in DrawMesh commands. /cc @Aras