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.

Problem multiple materials with Particle Renderer

Discussion in 'Editor & General Support' started by mas, Feb 14, 2011.

  1. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Hello,

    If I create a material array with the size of 3 in my ParticleRenderer , and set element0-2 to different materials .. all 3 materials are used on each particle. This means each particle that is created gives me the 3 overlapping textures.



    Anyone knows how I can get the renderer to take a random material when emitting a particle?

    (Ps. posted this earlier in some iOS topic - but reposted because I think this is a better place)
     
  2. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Can someone please confirm if this is a bug, a feature , or if I am just doing it the wrong way.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,352
    Yes, it's supposed to work like that. You'd need 3 separate particle systems if you want 3 separate materials.

    --Eric
     
  4. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Thanks for Your reply. Totaly unlogical IMHO , a three layered particle could easily be photoshopped. A material randomizer would be more usefull.
     
  5. eMilk

    eMilk

    Joined:
    Oct 22, 2009
    Posts:
    16
    Sorry for bumping ancient thread. Had the same problem, decided to do a quick fix, rather than create several particle systems. This short example here emits different pokemons.

    Assign the .js snippet below to the particle system you wish to assign a random material to.

    Pardon my ugly code.


    Code (csharp):
    1.  
    2. var pokemons : Material[];
    3.  
    4. function Update () {
    5.    
    6.     if (particleEmitter.emit){ // only do this random selection while actually emitting
    7.     if (pokemons.Length == 0) // do nothing if no pokemons
    8.         return;
    9.     var ichooseyou : int = Random.Range(0,pokemons.Length); // pick random pokemon
    10.     renderer.sharedMaterial = pokemons[ichooseyou];
    11. }
    12. }
    13.  
     
  6. Santokes

    Santokes

    Joined:
    Oct 26, 2011
    Posts:
    11
    Cool script eMilk

    This makes my particles flicker like mad: every frame they're choosing new materials.

    What you really want is for a newborn particle to pick a material, and stick with it for the remainder of its life.

    Really, the Unity particle system should be doing this already...