Search Unity

Mesh Particle Emitter Emit() crashing Unity

Discussion in 'Scripting' started by Joe ByDesign, Apr 17, 2007.

  1. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Hi people!

    I'm instantiating a mesh particle emitter prefab, set to self-destruct. Everything works fine, until i call .Emit() after instantiating, to which Unity replies with a big fat crash. Followed the docs on the creation of the emitter.

    Here is the instantiate clone code;
    Code (csharp):
    1.  
    2. particleClone = Instantiate ( particlePrefab, transform.position, transform.rotation );
    3. particleClone.particleEmitter.Emit();
    4.  
    Even tried calling Emit() from the particle itself (once cloned) but same behavior.

    Strangely, it works fine with Ellipsoid Particle Emitter.

    Anyone see this before?

    Full console error here:

    Code (csharp):
    1. =================================================================
    2. Got a SIGSEGV while executing native code. This usually indicates
    3. a fatal error in the mono runtime or one of the native libraries
    4. used by your application.
    5. =================================================================
    6.  
    7. Stacktrace:
    8.  
    9.   at (wrapper managed-to-native) UnityEngine.ParticleEmitter.Internal_Emit2 (UnityEngine.ParticleEmitter,int) <0x00004>
    10.   at (wrapper managed-to-native) UnityEngine.ParticleEmitter.Internal_Emit2 (UnityEngine.ParticleEmitter,int) <0xffffffff>
    11.   at UnityEngine.ParticleEmitter.Emit () <0x0007f>
    12.   at FX.SpawnParticles () [0x001a0] in /Users/Casemon/Documents/unity/projects/The Late Call/Assets/Scripts/FX.js:257
    13.   at FX.Update () [0x002be] in /Users/Casemon/Documents/unity/projects/The Late Call/Assets/Scripts/FX.js:207
    14.   at (wrapper runtime-invoke) System.Object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
     
  2. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Weirdness... if the particle emitter has both an ellipsoid mesh emitter it works (but uses ellipsoid)... remove the ellipsoid emitter and crash!

    Can anyone else quickly confirm that calling .Emit() (not .emit) on an instantiated mesh particle emitter (not ellipsoid) crashs or does not crash Unity?
     
  3. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Talking to myself here but if anyone has a moment to verify this, and doesn't mind possibly crashing Unity, here is a package to repro:

    a) Import the package and open the included "Mesh Particle Emit() bug" Scene.
    b) Click Play
    c) Press Space (warning, this will likely cause Unity to crash)

    KABLOOIE!
     

    Attached Files:

  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep...crash....

    --Eric
     
  5. hockeybag

    hockeybag

    Joined:
    Jan 25, 2007
    Posts:
    29
    I just discovered the same bug.

    I'm attempting to have rocks randomly scatter themselves around an area, and thought that using a mesh particle generator would allow me to get nice randomized locations on the landscape without having to code a lot of tedious math myself.

    Unfortunately, when I tell my landscape to "Emit()" stones, Unity crashes. When I comment that line out, it doesn't.

    I have submitted a bug report with the little Unity bug reporting app and included the URL of this thread.
     
  6. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    I have posted this bug a long time ago.. when i was trying to move some particle emitter to where some splash occurs.. i have uploaded a bug report but never had an answer or fix.

    Looking for some answers now

    .ORG
     
  7. hockeybag

    hockeybag

    Joined:
    Jan 25, 2007
    Posts:
    29
    I worked around it by setting all of the emitter properties. Then I run a coroutine that sets emitter.emit to true, yields, grabs the particles into an array, then sets emitter.emit to false. That gets me my particles with no crash, and allows me to loop through them and spawn an object at each particle location. It's a few lines more than emitter.Emit(10), but it'll do.

    Code (csharp):
    1.  
    2. var Stone : Rigidbody;
    3. var numberOfStones = 10;
    4. var upSpeed = 20;
    5. var upOffset = 2;
    6.  
    7. private var theEmitter : ParticleEmitter;
    8.  
    9. function Awake() {
    10.     theEmitter = particleEmitter;
    11.    
    12.     theEmitter.minEmission = numberOfStones;
    13.     theEmitter.maxEmission = numberOfStones;
    14.     theEmitter.worldVelocity = Vector3.zero;
    15.     theEmitter.localVelocity = Vector3.zero;
    16.     theEmitter.rndVelocity = Vector3.zero;
    17.     theEmitter.minEnergy = 1;
    18.     theEmitter.maxEnergy = 1;
    19.     theEmitter.emitterVelocityScale = 0;
    20.     theEmitter.emit = false;
    21.     StartCoroutine("spawnStones");
    22.  
    23. }
    24.  
    25. function spawnStones() {   
    26.     theEmitter.emit = true;
    27.     yield; // particles won't be available 'til next frame
    28.     var theParticles = theEmitter.particles;
    29.     theEmitter.emit = false;
    30.     for (var i=0; i<theParticles.Length; i++) {
    31.         var stoneLocation : Vector3 = theParticles[i].position;
    32.         stoneLocation += (Vector3.up * upOffset);
    33.         var aStone : Rigidbody = Instantiate(Stone, stoneLocation, Quaternion.identity);
    34.         aStone.velocity = Vector3.up * upSpeed;
    35.         yield;
    36.     }
    37. }
    38.  
    Alex.