Updated Unity and ParticleSystem stopped working

Hi there, I was having the same trouble as some other questions on this lecture regarding the Waves not being able to be moved to the control timeline.

After I updated to Unity 2023.3.0b3 (beta) and 2022.3.17f1 (stable), that problem went away but after reimporting everything the ParticleSystem got messed up.

Explosions works just fine but the lasers from the player’s ship barely work, and after couple seconds it stops working.

I did notice there’s a field for “max particles”, but setting it to a high value doesn’t do much.

I’ll post my Player code for reference and screenshots of my particle system config.

Thanks!

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerControls : MonoBehaviour
{
    [Header("General Setup Settings")]
    [Tooltip("Uses the new input system to get the player's movement")]
    [SerializeField] InputAction movementInput;
    [Tooltip("Uses the new input system to get the player's fire command")]
    [SerializeField] InputAction fireInput;

    [Tooltip("How fast the ship moves up and down based upon player input")] 
    [SerializeField] float controlSpeed = 10f;

    [Tooltip("How much can it move on the X axis")]
    [SerializeField] float xRange = 10f;
    [Tooltip("How much can it move on the Y axis")]
    [SerializeField] float yRange = 10f;

    [Header("Screen position based tuning")]
    [Tooltip("How much should pitch based on the position")] 
    [SerializeField] float positionPitchFactor = -2f;
    
    [Tooltip("How much should yaw based on the position")]
    [SerializeField] float positionYawFactor = 2f;

    [Header("Player position based tuning")]
    [Tooltip("How much should pitch based on the control signal")]
    [SerializeField] float controlPitchFactor = -10f;
    
    [Tooltip("How much should roll based on the control signal")]
    [SerializeField] float controlRollFactor = -20f;

    [Tooltip("Smooth factor so ship inclination movement doesn't look janky")]
    [SerializeField] float smoothInputSpeed = .1f;

    [Header("Laser gun array")]
    [Tooltip("Laser particle systems")]
    [SerializeField] GameObject[] lasers;

    Vector2 currentInputVector;
    Vector2 smoothInputVelocity;

    float horizontalThrow;
    float verticalThrow;

    private void OnEnable()
    {
        movementInput.Enable();
        fireInput.Enable();
    }

    private void OnDisable()
    {
        movementInput.Disable();
        fireInput.Disable();
    }

    void Update()
    {
        SmoothController();
        ProcessTranslation();
        ProcessRotation();
        ProcessFiring();
    }

    private void ProcessFiring()
    {
        var fireAmount = fireInput.ReadValue<float>();

        if (fireAmount > 0.5f)
        {
            ToggleLasers(true);
        } else
        {
            ToggleLasers(false);
        }
    }

    private void ToggleLasers(bool isActive)
    {
        foreach (var laser in lasers)
        {
            var emissionModule = laser.GetComponent<ParticleSystem>().emission;
            emissionModule.enabled = isActive;
        }
    }

    private void SmoothController()
    {
        Vector2 targetVector = movementInput.ReadValue<Vector2>();
        currentInputVector = Vector2.SmoothDamp(currentInputVector, targetVector, ref smoothInputVelocity, smoothInputSpeed);

        horizontalThrow = currentInputVector.x;
        verticalThrow = currentInputVector.y;
    }

    private void ProcessRotation()
    {
        float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;
        float pitchDueToControlThrow = verticalThrow * controlPitchFactor;
        float pitch = pitchDueToPosition + pitchDueToControlThrow;
        
        float yaw = transform.localPosition.x * positionYawFactor;
        
        float roll = horizontalThrow * controlRollFactor;

        transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
    }

    private void ProcessTranslation()
    {
        float xOffset = transform.localPosition.x + horizontalThrow * Time.deltaTime * controlSpeed;
        float yOffset = transform.localPosition.y + verticalThrow * Time.deltaTime * controlSpeed;

        float clampledXPos = Mathf.Clamp(xOffset, -xRange, xRange);
        float clampledYPos = Mathf.Clamp(yOffset, -yRange, yRange);

        transform.localPosition = new Vector3(
            clampledXPos,
            clampledYPos,
            transform.localPosition.z);
    }
}
![Screenshot 2024-01-21 104957|280x500](upload://cqQLH4FHMBNlEt4gArohUspD3Qi.png)
![Screenshot 2024-01-21 105028|268x500](upload://fkeZrKbIlvS45gv4QJrVmK9GMdh.png)
![Screenshot 2024-01-21 105036|432x248](upload://lVoALBieNwCGyeVi0796XnTFYlS.png)
![Screenshot 2024-01-21 105040|437x338](upload://641BZKJ8V7w94Lh7E9kIqZvYzvJ.png)

Hi Guilherme,

Please do not use any alpha or beta versions for developing your game. They are full of bugs.

Also do not import your project into multiple versions of Unity unless there is a very good reason for it. Whenever you switch versions, there is an additional chance to break your game. Without any backup, this means that you could lose your entire project.

Regarding the problem with the particle system, have you already tried to add Debug.Logs to your code to see what is going on during runtime? Since you mentioned that the particle system stopped working after a few seconds, maybe you will be able to figure the exact moment out.

What does ‘barely work’ mean? Were you able to detect a pattern?

The emitted particles must get destroyed after a couple of seconds. If they keep existing in the scene, it might be that the particle system stops working because of the ‘max particles’ value.

The particle system should also have ‘loop’ enabled. Otherwise, it stops emitting more particles. Since you don’t call Play() in your code, make sure ‘Play On Awake’ is enabled in the component to make it start automatically when setting enabled to true.

I hope this helped. :slight_smile:


See also:

Hi there!

I’ve learned my lesson the hard way, it definitely broke the game, and even updating to the next stable version didn’t help.

I’ve noticed that the particles are actually working, but what happens is that they become gradually transparent but collisions still works normally.

I’ve recorded a video showing the issue

Your video was really helpful. If you had described that, I probably would not have understood what you meant.

Did you modify the particle system yourself? If so, create a new particle system for testing purposes. Don’t modify any colours. Then test your game. If you don’t get the same problem, the problem is very likely a colour. In that case, you could either check the modules in your ‘broken’ particle system, or you could modify and test your new particle system. Once you get the desired result, you replace the old particle system with the new one.

If you get the same result with the new particle system even though you did not modify anything, there might be a problem with either Unity or your project. To check that, create a new project with a particle system. Test that particle system. If you get the same problem, the problem might be Unity. If you don’t get the same problem, the problem might be in your project.

Privacy & Terms