Cannot turn ParticleSystem on/off, and it keeps randomly disappearing.

Am I missing something here or is my Unity editor bugged? I cannot for the life of me figure out how to turn a ParticleSystem on/off in my scripts. I have tried all of the following pairs:

public ParticleSystem trail;

trail.enableEmission = true;
trail.enableEmission = false;


ParticleSystem.EmissionModule em = trail.emission;
em.enabled = true;
em.enabled = false;

None of these work. And I’m not getting a null reference either, I am positive I have correctly assigned the proper ParticleSystem to the variable “trail”.

On top of this, I’ll be testing things when I hit Play and suddenly I find that my ParticleSystem has just disabled itself for no reason. Sometimes when I press play it’s on, sometimes when I press play it’s off.

I am using Unity 2019.3.15f1. Is this an error on Unity’s part and should I re-download my editor? Or am I missing something painfully obvious? Thanks!

Okay so I made a big coding mistake. The trail that I am trying to access in the code above has actually been improperly assigned, I’m not grabbing the ParticleSystem that I’m seeing in game and that I want to edit.

At a certain point, I instantiate the weapon prefab that has the trail attached to it; when this occurs, a clone of the prefab is instantiated. So once I started applying this code to that clone that was instantiated, everything worked out!