- Home /
Code to turn off ParticleSystem doesn't turn it off in-game, but instead turns it off on the prefab permanently?
So I have the following code in my game for a ParticleSystem that is attached to my weapon:
[SerializeField] ParticleSystem weaponTrail;
private void Update()
{
if(Input.GetKeyDown(KeyCode.S))
{
weaponTrail.gameObject.SetActive(false);
}
}
When I press this in-game, it does not work; the ParticleSystem remains active. However, when I end the play session, and then hit play again, the ParticleSystem is deactivated. I have to then go into my prefabs and physically re-enable the prefab! I guess somehow my code is not responding in game but instead altering objects outside of it? How does that work, and how can I get it to work in game like any other object?
So I got everything to work when I moved around my scripts. Previously, I was trying to pass the actual ParticleSystem object to another script (one that manages the player's movement) and then do things with it there, but that was leading to the problem I described above.
Instead, I just made the ParticleSystem an object on my weapon's script, and did things with in on the weapon (and allowed other objects to call to the public functions on the weapon). So I fixed my problem, but I would still like to know why my original method was creating the problems it did.