Does vfx graph have analogue of rate over distance? I’ve found something called “Spawn over distance”, but it seems not working.
Hello!
Indeed the spawn over distance is your way to go if you need to spawn based on a moving position. Although it does not seem to work at first it needs to record a moving position every frame to compute the amount of particles to spawn: For instance the world position of the game object that holds the component.
The reason about this behavior is you do not necessarily need to use the owner position (for instance you would probably want to spawn based on a procedurally animated position)
Basically it expects a value that changes every frame to perform the computation. So providing the 0,0,0 local position every frame does not do much, but instead using a Change Space to convert the value into world space will do what you expect.
Also, this node does set two SpawnEvent attributes : position and old position, really useful if you need to distribute the particles in between the position and the previous position.
I’ve attached this sample effect so you can try it out. (It’s been made on the 4.6.0-preview of the package)
There is two another question.
- I got wierd behaviour when use flipbook player with 7x7(odd atlas size 3x3 5x5 f.e) atlas particles, sorta lagging twitching
- How to randomly pick frame from flipbook? Like in shuriken? I’ve got 4 debris pict in flipbook atlas, and i want to pick that one, randomly per particle
We’ll take a look about flipbook texture with odd dimensions to see if we can reproduce the issue.
Flipbook index is actually an attribute called “texIndex” (may be renamed in the future). So if you want to select a given frame randomly per particle just set the texIndex attribute to be random in the init context of your system. In you case a random number between 0 and 4 and set uv mode to be flipbook without interpolation in your output.
Hi Danua,
I can’t reproduce the issue you are experiencing with the odd atlas sizes (tried 7x7 with different flipbook player speeds and outputs, as well as both the flipbook and flipbook blend mode). The flipbook player math is quite simple (texIndex += FrameRate * deltaTime;) so there really shouldn’t be anything flipbook size-dependent.
I’d recommend checking if you may not be adjusting the texIndex attribute somewhere else in the graph. If you are still experiencing an issue, if you can share a video of the issue or the VFX asset itself, we can take a look.
https://www.youtube.com/watch?v=0P87QaxgHy0
Sorry for too long wait. I’ve try catch that bug whole that time, but i can’t, it’s always flickering when use uneven texture flipbook size
I have that bug too! It’s only appear when exit edit window, or enabling “Force runtime” When you edit effect, everything looks normal. And it have “burst once” (I make explosion so it need play only once)
Hi, i’m trying to make a brush stroke type with this without using the “setting position with random lerp” in Initialize.
This means i want Velocity Threshold to be say, 1. And Rate per Unit to be:
Distance (current Pos, old Pos).
But (i think) since the Spawn Over Distance node sets the oldPos at the “end” of the node, i can’t use the oldPos value to be used inside the node.
If i set RatePerUnit to like 50, and Velocity Threshold to 1, it does work like a brush but i want to control when i’m moving slow, to spawn accordingly.
Oh and i’ll use Line Output and use oldPos as targetPos; the main reason why oldPos has to accurately be the pos of the previous particle.
If all this is not possible, then i’m thinking of setting a Vector3 from C# called “oldPos”, in Update, and let some calculations for distance compared to that, and use a ConstantSpawnRate instead based on the distance.
Attached is what i’m trying to do (and some traces of failed attempts…)
Very helpful thread…
Thank you for the wonderful sample!
It was very helpful.
This sample interpolates the emitter position for each frame and seems to fill the random space between them with particles, but a gap like a picture was created with a fast bullet. Is there any good idea to solve this?
Does this still work in the latest version of unity? I can’t get anything to show on screen with the example
Nominating this post for the “add this to the docs please” award…
I wished I’d bookmarked all the similar head-slapping “ah! so that’s how it’s meant to be used!” posts I’m seen in the VFX graph threads. I could have put together some half-decent docs of my own by now
- Set “Space” to “World” in “Initialize Particle”
- Add “Set Position” block to “Initialize Particle” and set it to local 0,0,0
How could I increase a number value over time, is there a way to add 1 each frame until the value reaches 10 and then stop?
Hi @ManaWorksKirill ,
You can do something like this: create a custom attribute (named here MyValue) and set it in Initialize to 0 and increment it with a Set Custom Attribute block in Update (you can change it’s mode to Add in the inspector). You can then use a GetCustomAttribute node to check for the current value of MyValue, compare to see if it’s less than 10, and if so, add 1 to it in Update.
If you want this to happen per second, and not per frame, just multiply the result of the Branch node by Delta Time.
Note: to use custom attributes, you need to enable the experimental Operators/Blocks in Preferences - Visual Effects.
Hope this helps!
Hi, @ManaWorksKirill
Just to add to @VladVNeykov 's answer - there might be a simpler way to achieve what you want - if we knew what your actual end goal was.
(this is known as the XY problem - XY problem - Wikipedia - and I find it’s always worth asking for the implied question behind the question actually being asked)
For example if you just want a number cycling from 1 to 10 per frame then taking currentFrame % 10 would do the trick.
Thank you so much will test it out now!
Very new to this so I apologize for dumb questions. I’m using output mesh blocks in the VFX graph but they don’t come with a spawn, initialize and update blocks to animate them, for example, to change the size or change the material attributes assigned to them I need create a way for change over time to happen. I was trying to animate the exposed variables on the timeline but it doesn’t always work for me. The triggering doesn’t happen or not at the time I expected. So I want to do all the animation in the graph and have it happen after the VFX is spawned in the world. Thank you so much for looking at this.
-Kirill