can't assign material to trail render added by script

Hello, as the title says, in my code i’m generating a number of prefabs, and adding them the trail renderer component, and setting all of it’s parameters like startwidth and so on, is ok, but for some reason, i can’t apply a material to the trail renderer itself.
so the trail keeps on rendering with the “missing shader” magenta color.

I tried this way

		var trailcomponent = newplanet.GetComponent("TrailRenderer") as TrailRenderer;
		
		trailcomponent.renderer.material = dummy_mat;

//or...

		trailcomponent.renderer.materials[0] = dummy_mat;

none worked.
If i hadn’t randomly generated content, i could make a “trail prefab” and apply it, but it’s not my case. I need it to be added, and tweaked by code for each object.

thank you for your time :slight_smile:

I was having the same issue and by searching for it on google I found this answer post. Since there were no answer I tried once more to fix the problem. And the Editor shows up with the error message

Not allowed to access Renderer.material on prefab object. Use Renderer.sharedMaterial instead

So just use the trailcomponent.sharedMaterial instead or trialcomponent.sharedMaterials (for the array) and you can assign and change the materials as you like. Hope this helps anyone who mysteriously come across this question.

Regards.