Hello there !
Using VFX Graph, I’ve a periodic burst system and I’m looking to modify a value each time it’s bursting. Like once in two, the color is red, the other time it’s blue. I’ve thought about creating a custom attribute that I’m adding 1 each time it’s spawning (custom attribute block set to add), then do a modulo of 2, check if it’s equal to 0 and then output the result into a branch with my 2 colors. But that doesn’t work, it still outputs the same value. There’s probably something I didn’t get about custom properties so if you have any idea what I’m doing wrong/how to achieve this correctly, I’ll be glad to know !
Thanks in advance !
Hi!
I think the main problem is that you have that custom attribute per particle, so all the particles start with it at 0 and then increase it to 1 during initialize.
To me the best way to achieve what you are trying to do would be setting the color attribute directly in the spawner, and read it from each particle during initialize. You can use the Spawn State LoopIndex
variable to do the modulo, the way you were doing it before.
Something like this:
Please notice that the branch is directly providing a color, you can change the output type in the operator settings:
Hope that helps!
Hello !
Thanks for your reply ! It’s working well in this case but actually, I’m working with an Output Particle Shader Graph (quad)
which has a color input (that is working normally). But nothing appears when I’m doing the same setup but plugging the Get color Source
into my vector 4 input of my shader. The quad isn’t spawning at all.
You should use Get Color Current
in this case.
From the documentation: Get Attribute: color | Visual Effect Graph | 17.0.3
The location of the attribute. The options are:
• Current: Gets the value of the attribute from the current system data container. For example, particle data from a Particle System.
• Source: Gets the value of the attribute from the previous system data container read from. You can only read from this Location in the first Context of a system after a system data change. For example, in an Initialize Particle Context.
This means that when we use Source
in this case we are using the Color
attribute from the Spawner. This is only available during Initialize context.
You can transfer that color to each particle in Initialize with a Set Color
block, like the one you have (currently disabled). After that the particle color will be available in any other context, including the output, using Get Color Current
.
Have a nice day!
Looks like it’s working perfectly ! Thanks a lot !
I just have a bonus question ; Is it possible to have multiple values for an attribute ? For example, I wanna change the color but I’ve 2 input colors (Let’s say that in my shader I have a lerp between white and black, I want the white input to be X color and black input to be Y color). I still could use some compare nodes to check and modify the second color depending the first one (I hope it makes sense tho !) but is there an easier way using attributes to achieve this ? For example, I have an attribute color “a” and an attribute color “b” so I can use both of them separately ?
Sure, you can add custom attributes. The usage is not different from the standard built-in ones.
Use the blackboard to define a custom attribute for your secondary color:
You can find more information here:
https://docs.unity3d.com/Packages/com.unity.visualeffectgraph@17.0/manual/Blackboard.html#attributes