Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

3D Particles / Assets in 2D game?

Discussion in '2D' started by infinitypbr, Nov 14, 2013.

  1. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,914
    I'd like to use some of the 3D assets -- models, characters and most importantly particles -- that I've bought from the asset store in a 2D game.

    However, it looks like 3D assets can't be given a 2D layer, and so always seem to be rendered behind all the 2D stuff. Is it possible to somehow get the 3D assets to work in the new 2D system?

    Thanks!!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,149
    If a 3D object is positioned closer to the camera on the Z axis than a sprite, it's drawn on top, at least that I've seen.

    --Eric
     
  3. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,914
    Unfortunately it doesn't seem to work like that. It used to, but the new 2D version seems to keep all 2D stuff in front of all 3D stuff, regardless.

    It's difficult to tell, but the position of the particle is in front of the "ground" in this screen shot, but you can see the particle is being drawn behind all the 2D stuff. It's fairly large because the view camera is really close to it.

    I've been able to put 3D models in front of 2D stuff, however, but the 3D models don't seem to react to 2D colliders, as far as I can tell.

    $particle.jpg
     
  4. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    721
    For now you can assign renderers to sorting layers using code. See the Particle system that's in the Hierarchy of the 2D demo, it has a script to handle that.

    Should be something like

    Code (csharp):
    1. your3dgameobject.renderer.sortingLayer = "StringNameOfLayer";
     
  5. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,914
    Ah, perfect.

    This one line in a script attached to the object will work:

    Code (csharp):
    1. function Start () {
    2.     renderer.sortingLayerName = "Character";
    3. }
     
  6. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,914
    One followup @Will Goldstone -- is it possible to do a similar thing with the ordering? I wasn't able to find that in the demo scripts.