Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Importing particles with unique positions and velocities into Unity

Discussion in 'General Discussion' started by Gebray, Dec 3, 2021.

  1. Gebray

    Gebray

    Joined:
    Feb 26, 2021
    Posts:
    10
    Hi,
    I am here with only basic Unity skills. Currently I am working on exporting numerical simulation of fluids in unity. The numerical simulation is based on material point (the fluid is assumed as a collection of particles, with each particle having its position and velocity changing with time). My simulation result is given as a excel sheet containing each particle with its velocity, position and other particle parameters at specified time steps.

    Is there any way of importing the particles with their dynamic properties in unity and visualize the animation?

    P.S: I tried to read some about the possibilities and I am guessing two ways:
    1) Importing each particle as a game object and manipulating,but they are millions and from what I read performance is going to be an issue.
    2) Using particle system: I tried to place the particles on a user specified position vectors, but I don't know whether it is possible to manipulate each particle using velocity from external file.

    Gebray
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    ParticleSystem.SetParticles, pretty much.
    https://docs.unity3d.com/ScriptReference/ParticleSystem.SetParticles.html
     
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,616
    Yes it's certainly possible. The catch is that, being a game engine, Unity expects that you're able to write your own functionality for custom stuff like this.

    I'd suggest saving your data as a .csv file or similar, writing a class which can read that file and store the particle positions internally, and then a MonoBehaviour which uses it to set the position of particles using the method neginfinity pointed out above.

    If you're not sure how to do it, there are plenty of tutorials for C# about how to read text files, and then you can split them based on the comma character.
     
    Gebray likes this.