Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question How to make 2 particle systems behave identical when they are not start from scratch?

Discussion in 'General Graphics' started by baranovoblmivan936, Jan 19, 2023.

  1. baranovoblmivan936

    baranovoblmivan936

    Joined:
    Jan 19, 2023
    Posts:
    10
    There are 2 fire particle systems in scene, they are identical, same properties, same random seed.

    When I press Play button, they looks identical.

    But this seems only happened when 2 particle systems all start from scratch.

    What I really want to do is play first particle system start from scratch, and play second particle system 1 seconds later, and I hope second particle system behave identical to first particle system.

    I have tried to set second particle system's time same to first particle system, but still not work.

    I am out of ideas, is this possible?


    2 particle systems all start from scratch


    First started at 0s, second started at 1s and set time to 1s, they have same time, but still not identical, no idea why
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,248
    This strikes me as odd - what you are describing seems like it should work. If you are able to report it as a bug, with a link to this forum post and an example project, I will take a look.

    Thanks!
     
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,248
  4. baranovoblmivan936

    baranovoblmivan936

    Joined:
    Jan 19, 2023
    Posts:
    10
    Sorry for long wait, almost forget this.
    Anyway, I follow these but still can't make fire2 to exactly match fire1.
    Can you post whole working code?

    Project in attachments.
    Here's my code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. public class Control : MonoBehaviour
    7. {
    8.     public ParticleSystem fire1;
    9.     public ParticleSystem fire2;
    10.  
    11.     ParticleSystem.MainModule fire1Main;
    12.     ParticleSystem.MainModule fire2Main;
    13.  
    14.     bool _isFire2Played;
    15.     ParticleSystem.Particle[] m_Particles;
    16.  
    17.     void Start()
    18.     {
    19.         fire1Main = fire1.main;
    20.         fire2Main = fire2.main;
    21.  
    22.         m_Particles = new ParticleSystem.Particle[fire1Main.maxParticles];
    23.  
    24.         fire1.Stop();
    25.         fire2.Stop();
    26.  
    27.         fire1.Play();
    28.     }
    29.  
    30.     void Update()
    31.     {
    32.         Debug.LogFormat("<{0}> fire1.time:{1} fire2.time:{2}", Time.frameCount, fire1.time, fire2.time);
    33.         if (Time.time > 1)
    34.         {
    35.             if (!_isFire2Played)
    36.             {
    37.                 Debug.LogWarningFormat("<{0}> Paused", Time.frameCount);
    38.                 Debug.Break();
    39.                 _isFire2Played = true;
    40.  
    41.                 //Copy dafa from fire1 to fire2
    42.                 ParticleSystem.PlaybackState playbackState = fire1.GetPlaybackState();
    43.                 fire2.SetPlaybackState(playbackState);
    44.                 fire1.GetParticles(m_Particles);
    45.                 fire2.SetParticles(m_Particles);
    46.                 ParticleSystem.Trails trails = fire1.GetTrails();
    47.                 fire2.SetTrails(trails);
    48.  
    49.                 fire2.Simulate(fire1.time, true, true);
    50.                 fire2.Play();
    51.             }
    52.         }
    53.  
    54.     }
    55. }
    56.  
     

    Attached Files:

  5. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,248
    I'm not going to be able to produce an entire working sample for you.

    I can tell you though, those "Get" methods effectively retrieve a "keyframe" of the fire1 particle system, which you are then setting to fire2. So after you call the "Set" methods, fire2 should be in exactly the same state as fire1. However, you then call Simulate() with restart=true, which throws away the entire state of fire2 and simulates it again from the start. You should almost certainly just remove the Simulate() line.
     
  6. baranovoblmivan936

    baranovoblmivan936

    Joined:
    Jan 19, 2023
    Posts:
    10
    x2.png
    Comment out Simulate line, time not synced, two fire not identical

    x3.png
    Comment out Simulate line and Play line, time synced, but two fire still not identical

    x4.png
    Comment out Simulate line and move Play line to first, time synced, but two fire not identical


    I also try change method name from Update to LateUpdate, not work too
    What am I missing?
     
    Last edited: May 29, 2023
  7. baranovoblmivan936

    baranovoblmivan936

    Joined:
    Jan 19, 2023
    Posts:
    10