Forum rules - please read before posting.

Feature Request: Remember component on Particle Switch

It would mean a lot less faffing with variables if we could get a particle switch to remember its status after saving and loading.

Is this possible please?

Comments

  • Perhaps. What status specifically are you looking to save? It's on/off state, or e.g. how long it's been on for?

    Screenshots for context would be a big help.

  • Just on and off states. I have various particle effects in my scene, but it is uneconomical to have them running at all time, so I trigger them to turn on with the switch when the player approaches them. Then turn off when they are out of sight again.

    For them to load with the correct state I'm having to use Bools to track if they are on or off and triggering them as such through OnLoad. Remember Components would streamline this process a lot.

    I don't have many particle effects in my current project, but could imagine this becoming a nightmare to keep track of in a more complex scene.

  • Try this:

    using UnityEngine;
    using System.Collections;
    
    namespace AC
    {
    
        public class RememberParticleSystem : Remember
        {
    
            public override string SaveData ()
            {
                ParticleSystemData particleSystemData = new ParticleSystemData();
                particleSystemData.objectID = constantID;
                particleSystemData.savePrevented = savePrevented;
    
                ParticleSystem particleSystem = GetComponent <ParticleSystem>();
                if (particleSystem != null)
                {
                    particleSystemData.isPlaying = particleSystem.isPlaying;
                    particleSystemData.isPaused = particleSystem.isPaused;
                    particleSystemData.currentTime = particleSystem.time;
                }
    
                return Serializer.SaveScriptData <ShapeableData> (particleSystemData);
            }
    
    
            public override void LoadData (string stringData)
            {
                ParticleSystemData data = Serializer.LoadScriptData <ParticleSystemData> (stringData);
                if (data == null) return;
                SavePrevented = data.savePrevented; if (savePrevented) return;
    
                ParticleSystem particleSystem = GetComponent <ParticleSystem>();
                if (particleSystem != null)
                {
                    particleSystem.time = data.currentTime;
                    if (data.isPlaying)
                    {
                        particleSystem.Play ();
                    }
                    else
                    {
                        if (data.isPaused)
                        {
                            particleSystem.Pause ();
                        }
                        else
                        {
                            particleSystem.Stop ();
                        }
                    }
                    particleSystem.time = data.currentTime;
                }
            }
    
        }
    
    
        [System.Serializable]
        public class ParticleSystemData : RememberData
        {
    
            public bool isPaused;
            public bool isPlaying;
            public float currentTime;
    
            public ParticleSystemData () { }
    
        }
    
    }
    
  • Thank you.

    I haven't tested this but will save it for my next project since I've already setup the variables to remember if particle switches are on or off and with my deadline fast approaching I have no reason so change them for the script. This will be useful in the future though I am sure.

  • Could be useful,thanks Chris!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.