Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Collisions don't work with a particle system created via code

Discussion in 'Scripting' started by olimpiazam, Jan 15, 2024.

  1. olimpiazam

    olimpiazam

    Joined:
    Mar 16, 2022
    Posts:
    2
    Hi everyone, I'm working on a project where I create a particle system using a csv file where the id, x,y,z data are stored. The particle system is created correctly but although the "Collision" section in the Inspector is marked active (also Send Collision Messages), my particle system does not respond to collisions.
    If I place a 3d object with collider near the particles I don't receive any collision message.
    Here is part of the written code:

    Code (CSharp):
    1. private void CreateParticles()
    2.     {
    3.         rowCount = pointList.Count;
    4.         particlePoints = new ParticleSystem.Particle[rowCount];    
    5.      
    6.         for (int i = 0; i < pointList.Count; i++)
    7.         {
    8.             // Convert object from list into float
    9.             float x = (Convert.ToSingle(pointList[xColumnName]));
    10.             float y = (Convert.ToSingle(pointList[yColumnName]));
    11.             float z = (Convert.ToSingle(pointList[zColumnName]));        
    12.          
    13.             // Set point location
    14.             particlePoints.position = new Vector3(x, y, z) * plotScale;          
    15.          
    16.             // Set point size
    17.             particlePoints.startSize = particleScale;
    18.         }
    19.     }
    20.  
    21. private void OnParticleCollision(GameObject other)
    22.     {
    23.         if (other.CompareTag("Collider"))
    24.         {
    25.             Debug.Log("Particle collided with: " + other.name);
    26.         }
    27.     }
     
    Last edited: Jan 15, 2024
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,761
    olimpiazam likes this.
  3. olimpiazam

    olimpiazam

    Joined:
    Mar 16, 2022
    Posts:
    2