Search Unity

layers on instantiated prefabs

Discussion in '2D' started by Dmumzo, Dec 4, 2019.

  1. Dmumzo

    Dmumzo

    Joined:
    Nov 28, 2019
    Posts:
    8
    I have a gameobject "player" in whose code i instantiate a prefab (fireball projectile). Although I set the player to layer "player" (layer 8) and the prefab in layer "projectiles" (layer 9), when running the game the player is over, i.e. on foreground, the projectile.

    Why is that? How can I solve this?

    Thank you
     
  2. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    776
    The issue might be the Sprite Renderer Order In Layer rather than the Layer Mask.
    upload_2019-12-4_16-34-0.png

    You can set the Player's sorting layer to something like 10 and the fireball will be underneath the player always.