Forum rules - please read before posting.

"RememberParticle" script needed

Hello people!

I noticed this one:

I was in need of something that remembers if a light was on or off. Of course, this one worked like a charm even though I don't know the first thing about scripting (seeing that I had a step by step tutorial on how to write it).
Now I am in need of something that checks if a standart shuriken particle system is turned on, or off via the "Particle Switch" script (provided with AC).

Did someone already write this script or does someone need to write it anyways?
I'd be grateful if someone could help me out with that, seeing that I have no idea where even to start with it.

Comments

  • To elaborate:

    I startet building the particle script based on the light script that is 100% working:

    using UnityEngine;
    using System.Collections;

    namespace AC
    {
    [RequireComponent (typeof (Particle))]
    public class RememberParticle : Remember
    {
    public override string SaveData ()
    {
    ParticleData particleData = new ParticleData ();
    particleData.isOn = GetComponent <Particle> ().enable;
    particleData.objectID = constantID;

    return Serializer.SaveScriptData <ParticleData> (particleData);
    }

    public override void LoadData (string stringData)
    {
    ParticleData data = Serializer.LoadScriptData <ParticleData> (stringData);
    GetComponent <Particle> ().enable = data.isOn;
    }
    }

    [System.Serializable]
    public class ParticleData : RememberData
    {
    public bool isOn;
    public ParticleData () { }
    }
    }

    But of course, there was an error, so I couldn't even test it on an object:
    RememberParticle.cs(13,72): error CS1061: Type `UnityEngine.Particle' does not contain a definition for `enableEmission' and no extension method `enableEmission' of type `UnityEngine.Particle' could be found (are you missing a using directive or an assembly reference?)

    Which makes sense, considering that I don't know how to check if particles are on or off...
    So yeah! Any help is appreciated!

  • I'm not aware of a "Particle" class in Unity - the ParticleSwitch script affects the ParticleSystem component.

    In the SaveData function, set "isOn" to match the value of the ParticleSystem's isAlive property.  Then in LoadData, use the "isOn" to either call Play or Stop.
  • edited September 2016
    Yeah, your using the wrong type, man. It's not Particle it's ParticleSystem (I think Particle deals with individual particles instead), of course it's not going to find those methods if they're not there. Try using GetComponent<ParticleSystem>().enableEmission; instead. You should probably also take a look at the ParticleSystem API page in here.

    Edit: Oops, I mean, GetComponent<ParticleSystem>().Emission.Enabled. EnableEmission is already obsolete. So better safe than sorry.
  • This situation is a good reminder to humbly bow to people like Chris, for writing tools where people like me don't have to code. Because code is scary.

    I'll give it a whirl!
    Thanks guys!
  • Heya @Suro, did you ever get this script working?  Could I take a peek?  I'm needing to do something similar with a sequence in my game where I'm lighting candles in an old house.  I have the remember light script working just fine, just haven't looked at the particles yet and figured if you already had something up and running, I'd happily take it!  :D
  • @themightzq: One could be adapted from the RememberLight tutorial here.
  • Thanks @ChrisIceBox

    Yeah, I was planning on using the RememberLight script and started looking the messages above, I just haven't had a chance to look up the particle system calls from the script guide yet.  Figured if it was already done, I grab the script and move onto other things.  I'll try to dive in this weekend!

    Interestingly, I've discovered that my candles aren't remembering their material change either, so I'll have to look at that as well.  I have RememberMaterial on there...peculiar.
  • Be sure to place the materials (original and new) in a Resources folder and make their names unique.
  • Aha!  Yeah, didn't have the materials in the resources folder.  That got it working.  Thanks, man.  Time to look at the particles now.
  • edited March 2017
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    namespace AC
    {
    [RequireComponent (typeof (ParticleSystem))]
    public class RememberParticle : Remember
    {
    public override string SaveData ()
    {
    ParticleData particleData = new ParticleData ();
    particleData.isOn = GetComponent ().isPlaying;
    particleData.objectID = constantID;

    return Serializer.SaveScriptData (particleData);
    }

    public override void LoadData (string stringData)
    {

    ParticleData data = Serializer.LoadScriptData (stringData);
    if (data == null) return;
    if(data.isOn) GetComponent ().Play();

    }

    [System.Serializable]
    public class ParticleData : RememberData
    {
    public bool isOn;
    public ParticleData () { }

    }
    }
    }
  • Looks like that's working for me.  I had a buddy sanity check one line and I'm getting particles saved/loaded on my project.  I'll add this to the wiki as well.
  • Looks good, nice addition!
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.