Trail Renderer - starts at centre of screen for instantiated gameobject

Hi everyone,

I want to enable my Trail Renderer after a player gets to a certain level.

I have attached a Trail Renderer component on my Player prefab, and in the Player Script I have the following:

void Start () {

        if(GameManager.instance.level > 1)
        {
           GetComponent<TrailRenderer>().enabled = true;
        }
       
	}

My player prefab is instantiated at the beginning of every level at one side of the screen through a SpawnManager script. However, the trail renderer seems to show a trail from the centre of the screen at the beginning of the level for the first half a second which is frustrating.

I’ve tried invoking a function to delay when the trail renderer is enabled:

void Start () {

        if(GameManager.instance.level > 1)
        {

           Invoke("EnableTrailRenderer", 0.4f);
        }
  }	
    void EnableTrailRenderer()
    {
        GetComponent<TrailRenderer>().enabled = true;
    }

But this doesn’t work either. If I invoke this for any longer, then I see ‘Invalid AABB *this’ errors in my console, or my player up and disappears!

When I just have this enabled all the time (checkbox selected in Inspector), this behaves as expected.

Has anyone got any advice that could help?

Thanks!

Leo

Hello!

In the end I just had the trail renderer enabled to start with and reversed the code so it disables the trail renderer when level is less than the required amount.

Consider this workaround a fix if you ever encounter similar!

Thanks,

Leo