I have a particle system where i’m emitting particles at locations that I’m reading from a text file, like so:
string[] lines = textFile.Split('\n');
foreach (string line in lines) {
float[] position = new float[3];
float.TryParse(line.Substring(xCharStart, 8), out position[0]);
float.TryParse(line.Substring(yCharStart, 8), out position[1]);
float.TryParse(line.Substring(zCharStart, 8), out position[2]);
emitter.Emit(newVector3(position[0], position[1], position[2]), Vector3.zero, size, Mathf.Infinity, color);
Debug.Log("emitted a particle");
}
I’d like to do this in the editor so I can preview the particles when I select this particle system in the scene. I know particle systems that emit without script will simulate in the editor scene view when selected.
I have this working in an editor script, and my print statements are getting executed, however no particles are being emitted. I’m using the same code at runtime and the particles are emitted fine.
So, my question is, can I not use ParticleSystem.Emit() in the Editor? Or is something else going on?
Thank you!
I’m interested in the same thing! I have some effects that emit particles at specific locations. I’d like to preview the effect using something very similar to a particle system editor preview mode.
This is what I have so far:
EditorScript:
void EditorUpdate()
{
if(simulate)
{
Debug.Log(“.”);
myParticleSystem.Emit(pos, Vector3.zero, particleSize, particleLifetime, color)
}
}
When I hit an editor GUI button, it sets a the private “simulate” boolean to true, and the Debug.Log statement works. The particle system however doesn’t emit anything.
It seems like particleSystem.Emit(1) works from the editor, but not particleSystem.Emit(position,velocity,size,lifetime,Color)
Got it working, a little hacky but if you just set the particle system parameters manually and then call particleSystem.Emit(1); it works.
What I mean is, instead of calling
myParticleSystem.Emit(pos, velocity, particleSize, particleLifetime, color),
you have to do the following:
myParticleSystem.transform.position = pos;
myParticleSystem.startSize = particleSize;
myParticleSystem.startLifetime = particleLifetime;
myParticleSystem.startColor = color;
myParticleSystem.Emit(1);
It also seems that particles emitted this way from the editor won’t update. Meaning any time based parameter on the particle system won’t work. It also means that particles you emit won’t every get destroyed.
I’m getting around this by editing these parameters manually, and by removing the last particle in the particleSystem.particles array every time I add a new one once a certain threshold of particles has been emitted.
float threshold= 500; // or whatever you want
if (myParticleSystem.particleCount > threshold)
{
//create a new array to store particles
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[myParticleSystem.particleCount];
//store the particles
myParticleSystem.GetParticles(particles);
//copy particles, except the first one into a new array
ParticleSystem.Particle[] newParticles = new ParticleSystem.Particle[myParticleSystem.particleCount - 1];
for (int i = 1; i < myParticleSystem.particleCount; i++)
{
newParticles[i - 1] = particles[I];
}
//set the edited list of particles as the new list of particles
myParticleSystem.SetParticles(newParticles, newParticles.Length);
}
This isn’t perfect but works and will hopefully help someone out there! haha[/I]
Hello from future. Can we use ParticleSystem.Emit(EmitParams,1) now?