ParticleSystemDestroyer.cs(22,50): warning CS0618:

Anyone know how to fix this? Using Unity 5.51f1 (64bit)

UnityEngine.ParticleSystem.startLifetime' is obsolete: startLifetime property is deprecated.

Line 24: m_MaxLifetime = Mathf.Max(main.startLifetime, m_MaxLifetime);

using System;
using System.Collections;
using UnityEngine;
using Random = UnityEngine.Random;
namespace UnityStandardAssets.Utility
{
    public class ParticleSystemDestroyer : MonoBehaviour
    {
        // allows a particle system to exist for a specified duration,
        // then shuts off emission, and waits for all particles to expire
        // before destroying the gameObject
        public float minDuration = 8;
        public float maxDuration = 10;
        private float m_MaxLifetime;
        private bool m_EarlyStop;
        private object main;

        private IEnumerator Start()
        {
            var systems = GetComponentsInChildren<ParticleSystem>();
            // find out the maximum lifetime of any particles in this effect
            foreach (var system in systems)
            {
                m_MaxLifetime = Mathf.Max(main.startLifetime, m_MaxLifetime);
            }
            // wait for random duration
            float stopTime = Time.time + Random.Range(minDuration, maxDuration);
            while (Time.time < stopTime || m_EarlyStop)
            {
                yield return null;
            }
            Debug.Log("stopping " + name);
            // turn off emission
            foreach (var system in systems)
            {
                var emission = system.emission;
                emission.enabled = false;
            }
            BroadcastMessage("Extinguish", SendMessageOptions.DontRequireReceiver);
            // wait for any remaining particles to expire
            yield return new WaitForSeconds(m_MaxLifetime);
            Destroy(gameObject);
        }
        public void Stop()
        {
            // stops the particle system early
            m_EarlyStop = true;
        }
    }
}

Tried “main.startLifetime” and added “private object main;” under “monobehaviour”…

why? it’s complaining about obsolete code, i.e. “it doesn’t work this way anymore”. If you get an obsolete message you need to find a replacement

googled “unity particlesystem startlifetime obsolete replacement” and found
http://stackoverflow.com/questions/41393814/unity-5-5-obsolete-particle-system-code
which has a very nice explanation of what they did with it in the particle systems rehash recently.

1 Like

Fixed file.

ParticleSystemDestroyer.cs from Standard Assets.

using System;
using System.Collections;
using UnityEngine;
using Random = UnityEngine.Random;

namespace UnityStandardAssets.Utility
{
    public class ParticleSystemDestroyer : MonoBehaviour
    {
        // allows a particle system to exist for a specified duration,
        // then shuts off emission, and waits for all particles to expire
        // before destroying the gameObject

        public float minDuration = 8;
        public float maxDuration = 10;

        private float m_MaxLifetime;
        private bool m_EarlyStop;
        private static object main;

        private IEnumerator Start()
        {
            var systems = GetComponentsInChildren<ParticleSystem>();

            // find out the maximum lifetime of any particles in this effect
            foreach (var system in systems)
            {
                //m_MaxLifetime = Mathf.Max(system.startLifetime, m_MaxLifetime); //Deprecated
                m_MaxLifetime = Mathf.Max(GetStartLifetime(system), m_MaxLifetime); //Updated
            }

            // wait for random duration

            float stopTime = Time.time + Random.Range(minDuration, maxDuration);

            while (Time.time < stopTime || m_EarlyStop)
            {
                yield return null;
            }
            Debug.Log("stopping " + name);

            // turn off emission
            foreach (var system in systems)
            {
                var emission = system.emission;
                emission.enabled = false;
            }
            BroadcastMessage("Extinguish", SendMessageOptions.DontRequireReceiver);

            // wait for any remaining particles to expire
            yield return new WaitForSeconds(m_MaxLifetime);

            Destroy(gameObject);
        }
       
        //Added
        private static float GetStartLifetime(ParticleSystem system)
        {
            return GetStartLifetime(system);
        } 
        //End Added

        public void Stop()
        {
            // stops the particle system early
            m_EarlyStop = true;
        }
    }
}

Thanks for the read RightyLefty!