- Home /
Question by
benhumphreys · Jun 23, 2014 at 05:54 AM ·
randomparticlesystemshuriken
ParticleSystem.randomSeed doesn't work?
I'm trying to set the seed of a particle system so every time it's run, the particles move in the same pattern.
I've attached what I'm using below. What am I doing wrong?
using UnityEngine;
using System.Collections;
public class ParticleRandomTester : MonoBehaviour {
uint m_seed = 42;
ParticleSystem m_ps;
[SerializeField]
bool m_restart;
void Awake()
{
m_ps = gameObject.GetComponent<ParticleSystem>();
}
void Update()
{
if (m_restart)
{
m_restart = false;
Restart();
}
}
void Restart()
{
m_ps.Clear();
m_ps.Stop();
m_ps.randomSeed = m_seed;
Debug.Log("Setting seed: " + m_seed);
m_ps.time = 0;
m_ps.Play();
}
}
Comment
I've simplified this even further and still it runs differently every time.
using UnityEngine;
using System.Collections;
public class ParticleRandomTester : $$anonymous$$onoBehaviour
{
void Awake()
{
var ps = gameObject.GetComponent<ParticleSystem>();
ps.randomSeed = 42;
}
}
Best Answer
Answer by benhumphreys · Jul 08, 2014 at 09:57 AM
Nevermind I found the answer. You have to use Simulate to actually reset the ParticleSystem and get it to use the new randomSeed value. Stop and Clear don't help.
ps.randomSeed = 42;
ps.Clear();
ps.Stop();
ps.randomSeed = 42;
ps.Play(); // Nope
// Yup
ps.Simulate(0, true, true);
Thanks for this. I was seeing the same behavior in 5.4.0f1
Your answer
