Search code examples
unity-game-enginerenderer

So my bullet prefab shows trail when dragged into the scene But not when I play it


So when in scene mode the bullet prefab shows the trails but when I hit the play button it doesn't show any trails whatsoever. I am trying to make a top down shooter with unity. I am new to this, please help much appreciated.

While playing it doesn't show the trail

When in scene mode it shows

Trail renderer settings


Solution

  • You can set the order of the trail renderer in Trail Renderer > Additional Settings > Order in Layer.

    For an older version of Unity layer ordering variables are not exposed in the inspector. You can write a custom script that sets the sorting layer / order.

    public class RendererSortingLayer : MonoBehaviour
    {
        public string sortingLayerName;
        public int sortingOrder;
    
        void Awake()
        {
            Renderer renderer = this.GetComponent<Renderer>();
            renderer.sortingLayerName = sortingLayerName;
            renderer.sortingOrder = sortingOrder;
        }
    }