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

Question [SOLVED] How can I change a colour of certain particles?

Discussion in 'Visual Effect Graph' started by SadShadyBoi, Dec 22, 2022.

  1. SadShadyBoi

    SadShadyBoi

    Joined:
    Oct 9, 2020
    Posts:
    10
    Hi! I am very new to VFX Graph and I've been playing around with it lately.

    I have a VFX Graph which displays particles in specified locations (via raycast and the locations are stored on a texture2d via colors). Right now I have a simple gradient that will change the color of particles based on the distance form the player.

    My question is: Is there a way to specify which gradient a certain particle can use depending on an object hit?

    For example: If my raycast hits an object with the tag "Environment" it will use Gradient A but if I hit an object with the tag "Enemy" it will use Gradient B?

    I've tried using Events and different attributes but nothing worked so far.

    Thank you for any help.
     
  2. mk4blogging

    mk4blogging

    Joined:
    Dec 22, 2022
    Posts:
    4
    When a particle system has multiple colors, each color is assigned a color scheme. To change the color of a particular particle, you must first make sure that you’re viewing the color scheme you’re interested in in the particle system view, as seen in the figure below. Once the color scheme is selected, double-click a particle in the particle system to select it. A pop-up menu will appear, as shown in the image below. Select the desired color from the list, and click OK. For more information visit us.
     
    Last edited: Dec 27, 2022
  3. SadShadyBoi

    SadShadyBoi

    Joined:
    Oct 9, 2020
    Posts:
    10
    I'm not sure if i understand what you mean. You cannot select one particle from a system in editor. And even if I do not wish for a manual solution.

    I'm aiming for a solution during runtime that will automatically change the gradient particles will use based on the object tag a raycast has hit.
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,294
    Assuming you have all needed data you need to somehow assign property to particles that indicates what was hit. You can use your own attribute or use some existing like texId and this will be the "id" of the gradient you want. It can be also normalized float, it's your choise. Then you need to generate (probably in editor, but can be in runtime too) texture that is kind of list of gradients - each row represents gradient. You can use previously stored particle data to sample the row you need. For example your UV can be (age, id) or (distance, id).

    In theory you could use large switch of gradients, but I am not sure what is performence of that, plus it's not handy, you would need to expose a lot of properties to make it customizable during runtime (max 32).
     
  5. SadShadyBoi

    SadShadyBoi

    Joined:
    Oct 9, 2020
    Posts:
    10
    So would an easier solution be creating more systems for each gradient type? I'm predicting no more than 4 different tags to hit. I could track different systems and the particle positions. It sounds like an easier solution than trying to figure out how to pass more data into a graph.
     
  6. SadShadyBoi

    SadShadyBoi

    Joined:
    Oct 9, 2020
    Posts:
    10
    Or to simplify things even more. Let's just change the colour of a particle depending on a tag. Could using a graphics buffers be an easy workaround?
     
  7. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,294
    I don't know your requirements, it's up to you, but I see no special reason to make 4 systems if one can handle it. Also if you are very sure there gonna be only 4, then you could just go away with switch of gradients, but it's not like 4 systems way is bad.
    Whatever it going to be gradient or single color you would need to use buffer (or texture) anyway to initialize them with some unique properties (unless you go with separate systems).
     
  8. SadShadyBoi

    SadShadyBoi

    Joined:
    Oct 9, 2020
    Posts:
    10
    Right that makes sense. My issue then would be (mostly because I'm a noobie with VFX) how to prevent the entire system from changing colour. No matter where I put the "Set Color" node as soon as I hit a different object the entire system would change colour.
    I'm sorry if this is a stupid question, I'm really a bit confused by it. Not sure how to change the colour for just some particles.
     
  9. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,294
    Ok, let's go with simple example - particles with different colors. There are two ways you either put that data directly into particle (like size, position or color) or you assign some data that can be used to create desired effect.
    In the first case you can just run Set color once in initialize at the beggining and modify this value in update or output if you wanted. In the second case you set some special value used in output or update to create some desired effect, this is how texId is used in flipbook, it does not store texture inside particle (not even possible), but instead it's index of image to display, so output can calculate proper UV frame.

    You can do yours in the same way - sample buffer in initialize to get proper data for every spawned particle, let it be int 0-3, each repreents different tag in your game. Then you can use this value to feed switch node with gradients, colors or whatever else you need, and it will return corresponding value.
     
    SadShadyBoi likes this.
  10. SadShadyBoi

    SadShadyBoi

    Joined:
    Oct 9, 2020
    Posts:
    10
    Oooh okay thank you! I'm sorry it took me so long. I'm still figuring out how the VFX Graph works. I will play around with these methods.

    You're a godsend thank you very much for your help! I should be fine from now on.