2D Orthographic Cameras and Line/Trail Renderers Not Working (with detailed example)

So there are tons of questions out there about orthographic cameras + LineRenderer or TrailRenderer not working together or working strangely together, and I think I’ve read a hundred of them. Still - I can’t get them to work together.

I’ve laid out an extremely simple example using TrailRenderer instead of LineRenderer for simplicity, but they share the same problem. The basic issue is that although I can see my Lines/Trails in the Scene view, they don’t show in the Game view.

The Example:

Simple Movement Script:

public class SimpleMovement : MonoBehaviour {

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		int horizontal = 0;
		int vertical = 0;
		horizontal = (int)(Input.GetAxisRaw ("Horizontal"));
		vertical = (int)(Input.GetAxisRaw ("Vertical"));

		Vector2 start = transform.position;
		Vector2 end = start + new Vector2 (horizontal, vertical);
		Vector2 newPosition = Vector2.MoveTowards (start, end, .1f);
		transform.position = newPosition;

Things I’ve tried:

  • Playing with every permutation of Sorting Layer and Z-values
  • Camera.transparencySortMode and Camera.opaqueSortMode
  • Using a different Orthographic camera than one attached to Unit
  • Madly changed every value I could find in every possible way all the while laughing hysterically

I’m hoping that if I can solve this problem with the TrailRenderer I’ll be able to fix my real problems with LineRenderers + TrailRenderers in my actual game. Any help is super appreciated, so thanks in advance.

Happy Holidays.

Okay so the answer was in SortingLayers. The most important bit I noticed is that no matter what the parent GameObject is set to, I still needed to set the SortingOrderName for the TrailRenderer component in the script, otherwise it would just always render behind every other sprite regardless of Sorting Layer or Z value.