Topic: Reset to simulation speed 1 for particle when clone in UFE 2.6.0

When simulation speed is 5 or 2 or greater than 1 in particle prefab, then when prefab is clone from moves projectile, then simulation speed is reset to 1 in all particles.
It is breaking our game and not found any fix for this until now.

Share

Thumbs up Thumbs down

Re: Reset to simulation speed 1 for particle when clone in UFE 2.6.0

I see the problem.
With UFE 2.6.0 now controlling particle simulations, it overrides the speed with its own time scale.
The solution would be to add a backup value of the original speed and add it as a multiplier on top of the time scale applied.

Try these changes. I just made them and committed to the repository. I'll issue an update soon.

Under InstantiatedGameObject.cs, you will find a definition for particles like so:

public ParticleSystem[] particles;

Change it to this

public Dictionary<ParticleSystem, float> particleStorage;

(Make sure you also change the constructors)


Now under UFE.cs look for this code (line 2085):

ParticleSystem[] particles = goInstance.GetComponentsInChildren<ParticleSystem>(true);
foreach (ParticleSystem particle in particles)
{
       particle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
       particle.randomSeed = (uint)creationFrame;
}
UFE.instantiatedObjects.Add(new InstantiatedGameObject(uniqueId, goInstance, mrFusion, particles, creationFrame, creationFrame + durationFrames));

And change to this:

ParticleSystem[] particles = goInstance.GetComponentsInChildren<ParticleSystem>(true);
Dictionary<ParticleSystem, float> particleStorage = new Dictionary<ParticleSystem, float>();
foreach (ParticleSystem particle in particles)
{
        particle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
        particle.randomSeed = (uint)creationFrame;
        particleStorage.Add(particle, particle.main.simulationSpeed);
}
UFE.instantiatedObjects.Add(new InstantiatedGameObject(uniqueId, goInstance, mrFusion, particleStorage, creationFrame, creationFrame + durationFrames));

Now under MatchManager.cs, look for this code (line 274):

foreach (ParticleSystem particle in entry.particles)
{
    var mainModule = particle.main;
    mainModule.simulationSpeed = (float)UFE.timeScale;
    float time = (currentFrame - entry.creationFrame) / (float)UFE.fps;
    particle.Simulate(time, true, true, true);
}

And change it to this:

foreach (KeyValuePair<ParticleSystem,float> particleData in entry.particles)
{
    var mainModule = particleData.Key.main;
    mainModule.simulationSpeed = (float)UFE.timeScale * particleData.Value;
    float time = (currentFrame - entry.creationFrame) / (float)UFE.fps;
    particleData.Key.Simulate(time, true, true, true);
}

These changes should make it so UFE doesn't directly interfere with the original simulation speed value.

Like UFE? Please rate and review us on the Asset Store!
Questions about the Forum? Check out our Karma FAQ.

Re: Reset to simulation speed 1 for particle when clone in UFE 2.6.0

Thank you so much.

Share

Thumbs up Thumbs down