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?
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:
Make the Visual Effect Graph on a new “UI FX” layer
Create an FX Camera that only looks at the “UI FX” layer and ignore this layer in your main Camera
Make the FX Camera output into a Render Texture with some fixed size
Use the render texture in a Visual Element (matching the size)
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.
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.
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.
Set up a particle system and tag it as some kind of effectsLayer
Create a new camera that only sees the effectsLayer
Use a render texture in the camera output
Create an absolutely positioned visual element with a background set to the same render texture from 3
Ended up with something like this
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