Particle Effects and UI Toolkit

Hello, we are in the process of polishing our UI a little, and we would like to add some visual effects as feedback for the player when certain actions are triggered.

The only process we could find to add something animated is by using sprite sheets or sprite atlases (added quite recently).

So, our process right now is:

  • Prepare a scene with a Visual Effect Graph effect and a Camera
  • Use Unity Recorder to save an image sequence
  • Use Unity Sprite Atlas to merge all the frames together
  • Create some code to apply the sprite atlas to an Image component and change its source rect to “animate” the sprite.

The results are something like this:
spiritednastyfawn

In this thread , @benoitd_unity suggested something about an hybrid Component, can someone help us with that?

Hello,

Not sure what @benoitd_unity suggested is related.

Your approach works well because it precomputes the effect ahead of time.
Another similar solution would be to utilize Render Textures.

Here is how you could approach this:

  1. Make the Visual Effect Graph on a new “UI FX” layer
  2. Create an FX Camera that only looks at the “UI FX” layer and ignore this layer in your main Camera
  3. Make the FX Camera output into a Render Texture with some fixed size
  4. Use the render texture in a Visual Element (matching the size)
  5. Make that element “position: absolute” in USS and “picking-mode=Ignore” in UXML so it doesn’t catch any event

In the preview.9 you can now assign a render texture to VisualElement.style.background.
The next version will support this in USS directly. Once this is available I will share a quick sample here.

In a future version we would like to have a more natural way to support this without Render Textures.

Hi @antoine-unity , thanks for your reply.

Using render texture seems appealing, but then I though that we would have to do one camera & texture for each effect, and we did have some performance impacts on doing that.

So, we think we will proceed like this:

  • Create VFX + Camera render texture like you propose for sketching up the effect (type, color, etc).

  • When the VFX and Camera position look good in real time, use Unity recorder to record that particular camera output into an image sequence.

  • Sprite atlas the recorded images and flip it at runtime.

That seems like the quickiest way to sketch & put in production a particle / vfx effect.

Thank you!

Yeah, that sounds like a good enough approach.

The Image class also has the ability to render a RT, with the added benefit of only rendering a subregion of the texture (through UV). So in theory this may allow you to have a single RT for multiple effects on different elements at the same time.

I am now facing exactly the same problem. Is there currently a better or other way?

I ended up similar to the above:

  1. Set up a particle system and tag it as some kind of effectsLayer
  2. Create a new camera that only sees the effectsLayer
  3. Use a render texture in the camera output
  4. Create an absolutely positioned visual element with a background set to the same render texture from 3

Ended up with something like this
8370942--1103259--coinfx.mov.gif

I am crossing my fingers that this won’t be too expensive on mobile devices
but maybe unity will have some solutions by the time I hit production ‍
¯_(ツ)_/¯
probably not