Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Trail Renderer not rendering in Play Mode

Discussion in '2D' started by PaRsOnIsPhErE, Jun 7, 2020.

  1. PaRsOnIsPhErE

    PaRsOnIsPhErE

    Joined:
    Dec 19, 2018
    Posts:
    19
    Hi all,

    I've having some trouble with trail renderer component. I've searched high and low for similar problems with others and attempting the fixes that have been mentioned, but clearly nothing so far.

    In a nutshell I have created a new gameobject and added a trail renderer to it. I have then placed this object as a child of my player. When moving the player object around the scene view I am able to see the trail, as well as in the game view (see below image). But when launching game in play mode, there is no trail too be seen, just the ship sprite....



    Below is a photo of my PlayerShip prefab hierachy and the trail being displayed in the view.


    Here is a photo of my trail renderer settings in the inspector tab.



    Here finally is the inspector tab settings / components for the parent object, PlayerShip.



    Thank you in advance all for any help, advice or tips you pass on. I owe you a beer if we ever meet up!
     
  2. PaRsOnIsPhErE

    PaRsOnIsPhErE

    Joined:
    Dec 19, 2018
    Posts:
    19
    So I've narrowed it down to the fact that the trail object is not following my ship, so I have added the below code to the trail object, which has helped, as the trail now appears in play mode.

    Code (CSharp):
    1.     public Transform PlayerShip;
    2.  
    3.     // Update is called once per frame
    4.     void FixedUpdate()
    5.     {
    6.         gameObject.transform.position = new Vector3(PlayerShip.position.x, PlayerShip.position.y + 0.27f, PlayerShip.position.z);
    7.     }
    8. }
    But only when manually moving the ship via the scene view. When using the joystick on the controller, using PlayerInput the trail object decides not to follow the ship... going back to manually moving the ship, the trail object now follows but from it's current location.... so basically....

    (PlayerShip)(Trail) Move manually in scene and you still have that, and all is showing correctly.

    (PlayerShip) (Trail) Move ship using PlayerInput and it moves away from the trail object with the trail object staying where it is... when then going back to moving the ship manually the trail starts from it's location away from the ship...

    I am happy to provide info you may need, to let me know where i'm going wrong, just a nudge in the direction as to why it's not working would be great. Thanks again all!