- Home /
how can I get particle.position out of shuriken system?
I've been searching around quite a bit on this, and I've seen a lot of people setting particle locations, but I'm using the particle system to generate a large cloud of points which I then want to extract and instantiate prefabs.
I feel like I'm missing something very simple here, but I can't get particle.position information without using OnParticleCollision.
GetParticles() returns the number of particles, and Particle[] mypoints = ps.Particle[]; gives the error "cannot convert to UnityEngine.Particle type from UnityEngine.Particlesystem.Particle"
which seems fairly ridiculous to me. Anyway, what am I missing here?
Thank you
Answer by CodeMasterMike · Oct 24, 2012 at 07:51 PM
It's quite a old question, but I thought I could mention,in case someone else is wondering, how to access a single particle with c#.
This example I am changing the velocity for each individual, active particle. Important is to set the particles back (SetParticles()) after you have done some changes to the particles. Or else they will have the old values.
ParticleSystem m_currentParticleEffect = (ParticleSystem)GetComponent("ParticleSystem");
ParticleSystem.Particle []ParticleList = new ParticleSystem.Particle[m_currentParticleEffect.particleCount];
m_currentParticleEffect.GetParticles(ParticleList);
for(int i = 0; i < ParticleList.Length; ++i)
{
ParticleList[i].velocity = m_windDirection;
}
m_currentParticleEffect.SetParticles(ParticleList, m_currentParticleEffect.particleCount);
Note that if you use SetParticles() you will get the particle culling bug I describe here. If I am not mistaken, that is. If I am, please let me know in that thread - still looking for a solution.
Answer by DaveA · Sep 11, 2012 at 07:18 PM
It returns the number of particles AND the list of particles. Which is redundant but hey. Try
var myParticles : ParticleSystem.Particle[];
function Start()
{
....get the particle system component...
myParticleSystem.GetParticles (myParticles);
now myParticles should have the list of particles.
Hmm, I've tried that (in C#) and it doesn't appear to work. myparticles still shows as (null) even after doing particleSystem.Emit(30), and if I try to assign myParticles = myParticleSystem.GetParticles(myParticles); it throws the error that I cannot convert UnityEngine.ParticleSystem.Particle to Particle.
In c# it should look like this:
ParticleSystem.Particle[] myParticles;
myParticleSystem.GetParticles (myParticles);
the conversion error has to do with there being two kinds of particles, shuriken and legacy, so you have to make sure your array is the right kind.
Your answer
Follow this Question
Related Questions
Setting particle position every frame... 1 Answer
Particle System Using Code 0 Answers
Multiple Cars not working 1 Answer
Changing particlesystem at runtime 0 Answers
Why does my particle system get enabled with a delay? 2 Answers