Search Unity

Free Script - Particle Systems in UI Screen Space Overlay

Discussion in 'UGUI & TextMesh Pro' started by glennpow, May 26, 2016.

  1. lc0030

    lc0030

    Joined:
    Oct 25, 2017
    Posts:
    1
    Works nicely, but for some reason X and Y rotation doesn't work, any idea?
     
  2. chenghuisun

    chenghuisun

    Joined:
    Jun 20, 2014
    Posts:
    3
    well done! but GC is very high every frame. About 0.5Kb GC Per One UIParticleSystem. Have a idea to remove GC?
     
  3. jingray

    jingray

    Joined:
    Feb 6, 2015
    Posts:
    53
    Cools. Thank you !
     
  4. maurojuarez

    maurojuarez

    Joined:
    Jan 20, 2017
    Posts:
    1
    If you are on a Unity version between 5.4 and 2017.2, you can reduce the GC Alloc by using Reflection instead of calling the Unity API ParticleSystem.Simulate()
     
    Last edited: Feb 1, 2018
    super77gg likes this.
  5. sp-sergio-gil

    sp-sergio-gil

    Joined:
    Mar 5, 2014
    Posts:
    45
    Hi All!!

    I'm testing this approach with Unity 2017.2.1p2 because I'm really interested in find a correct solution for using 2D + 3D + 2D in Unity UI and profiling the system (the scrips + shaders used are from unity ui extension) I can notice very big spikes produced by LateUpdate calculations... I don't now if this can be optimized some way... I will take a look at the script and shaders to see if I can do something more but right now I have the feeling that this approach is not working very performant?

    profiler.png

    Sergi
     
  6. Miranas

    Miranas

    Joined:
    Feb 21, 2018
    Posts:
    1
    thank thank very muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuch thank you :p:D Good Job!!!!!!!!!!!!!!
     
  7. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    904
    You can get fantastic performance even on lower end Android devices by simply rendering a normal particle system to a render texture, then using a RawImage UI component anywhere on your canvas to see the resulting particles. It causes remarkably little overhead and avoids all of this weird hacking of the particle system advocated within this thread.
     
    StupydHors and tasume like this.
  8. MODev

    MODev

    Joined:
    Jul 30, 2013
    Posts:
    229
    @Claytonious with this way, he will need to make high-res render texture and this will cost a lot of memory, especially if someone wants to add multiple particles. Additionally this solution doesn't allow you to make for example particles flying around GUI element
     
    SweatyChair likes this.
  9. GainPlay

    GainPlay

    Joined:
    Jan 29, 2015
    Posts:
    4
    This looks to be a fantastic script. In the editor it works like a charm. In Play mode however nothing shows up, the script is turned off by default and when I turn it on this error gets spammed:

    ArgumentNullException: Value cannot be null.
    Parameter name: shader
    UnityEngine.Material..ctor (UnityEngine.Shader shader) (at C:/buildslave/unity/build/Runtime/Export/Shader.bindings.cs:97)
    UnityEngine.UI.Extensions.UIParticleSystem.Initialize () (at Assets/Source/Scripts/Particles/UIParticleSystem.cs:74)
    UnityEngine.UI.Extensions.UIParticleSystem.LateUpdate () (at Assets/Source/Scripts/Particles/UIParticleSystem.cs:330)

    Anything I can do to make it work?
     
  10. zygi50

    zygi50

    Joined:
    Jun 15, 2018
    Posts:
    1
    If you copied first full script without adding anything commenting line "69" fixed it for me :)
    to be sure, line code you need to comment:
    Material material = new Material(Shader.Find("UI/Particles/Hidden"));
    or you can download that shader.. and let it work
     
    Last edited: Jul 26, 2018
    Ivanisov-Vitaliy likes this.
  11. Ramphic

    Ramphic

    Joined:
    Jun 21, 2017
    Posts:
    60
    Hi, @glennpow, how to enable and disable particle system properly, considering memory and cpu usage?
     
  12. Rock360

    Rock360

    Joined:
    Oct 26, 2016
    Posts:
    8
    rkvieira, khaled24, chao_xu and 3 others like this.
  13. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Looks fantastic but I find it impossible to use the Renderer + Texture Sheet Animation to use a sprite from an atlas (sprite sheet) that contains all my UI elements: the ui-extension UI Particle System script generates particles using the material referenced in the material field of said script, but materials don't allow for the use of elements picked from atlases.

    Then Unity's Particle System component also generates a second set of particles with its Renderer block active, using Sprites-Default as the material, using billboard display, and "sprites" mode in Texture Sheet Animation instead of "grid".
    This second set allows me to use any of my elements from my UI atlas, BUT... they are displayed behind any other UI element using the UI image component.
    I tested with different rendering orders and layers but nothing changed. I (desperately) moved the uGUI elements on the Z axis too but it didn't work.

    Setting the ui-extension UI Particle System script's material with UIParticleHidden shader does hide the particles created by the ui-extension script, that's good.
    (Note: changing the material in the script automatically deactivates the renderer so you have to activate it again.)

    So for this system to work, I would need to have the second set of particles generated by the Renderer block to be displayed in front of all the UI elements of the UI layer.
    The problem is that when in 3D view, it's obvious that even using the Sprite-Default material, the elements are rendered in the 3D world instead of being pushed into the 2D plane of the canvas.

    Is there a way around this without messing with coding?
     
  14. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    To make it clearer, the custom UIParticleSystem script hacks Unity's component (Particle System) and generates its own set of particles : they are properly rendered into the 2D plane of the UI, but they don't allow the user to pick graphic elements from an atlas/sprite sheet.
    The script uses most of the native Particle System's functions and options, but ignores the Renderer.

    Meanwhile, the Renderer + TSA blocks of the native Particle System enable the use of atlases, but the particles are rendered in the 3D world, so behind the UI.

    The only way to use an atlas is through the Renderer, which the script does not recognize.

    IMHO, for this to work, the ui-extension UIParticleSystem script would have to be modified in order to check if the Renderer block is active, then use the material(s) referenced in this block instead of the one in its own material field.
    Perhaps by also tweaking the Renderer block so it behaves like the component Canvas Renderer + Image.

    I have a hard time believing that since Unity 5 is out, they never thought of allowing their nice particle system to work in the GUI overlay too. That is just so weird considering how obvious it would be, especially for 2D games.
    They have all the tools but it looks like a bridge is missing.
    Or did I miss something?
     
    Last edited: Apr 7, 2019
    twhittaker likes this.
  15. MODev

    MODev

    Joined:
    Jul 30, 2013
    Posts:
    229
    Well you can always use one of available solutions from asset store (just type gui particles in search), maybe one of them will fit your needs?

    Edit: or maybe you could try to make script which uses sprite properties (so sets its texture - even if it's atlas, set scale and offset inside material to fit sprite position on atlas) and handle sprite animations like that if something doesn't work with default free script?
    About being rendered behind or in front: well it requires some more effort but in free solution you can still try to handle this by rendering queue. (I hope I understood you well in this case)
     
    Last edited: Oct 1, 2018
  16. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Thanks for the reply,
    Some of these uGUI particles solutions seem adequate, but what, they tend to be expensive! Around $25-30 (!!!) just to push an already existing particle system onto the UI layer??? : /
    Perhaps I'm not realizing the amount of efforts put into these "dem particulz in ur ui" plugins but really, it's insane that Unity doesn't handle that natively! Imagine a 2D engine that couldn't display particles, this would be quite ridiculous!
    I understand Unity likes to sell plugins and options like cakes but here it's borderline abusive and very disappointing.
    Looking at all the hacks and "solutions" people had to come up with and were always average at best, that's rather sad.

    In terms of priorities, this feature was requested since 2014 but its priority remains at doormat level at best.
     
    florianBrn and Storm4_ like this.
  17. MODev

    MODev

    Joined:
    Jul 30, 2013
    Posts:
    229
    Well it depends on what you need. For example if you have 2d engine particles are also flat and on one plane. In unity you can make things working pretty well for 2d scene with sprites. But in your case it's not sprite system for 2d game but optimised gui system which works differently (because of batching, etc) .
    About the price: yes it requires much effort to handle this and if you compare price to time needed for programmer to deal with all problems those things are not so expensive. Especially they may have features that you may not need at first view but later they are life savers (like culling masks for 3d particles). And even for those assets not everything is possible like one doesn't support 3d particles or second screen space gui without camera attached.
     
  18. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Okay I still think it's expensive but if at least one of them can make the native particle system work in the UI layer with ALL functions, including the Renderer and the Texture Sheet Animation, then I guess that if a solution can't be found for the ui-extension asset, well, I'll have to go shopping... again (sigh).
     
  19. Vendrad

    Vendrad

    Joined:
    Jan 8, 2016
    Posts:
    4
    When "Play on Awake" is deselected. The particle system always plays anyway. I'm using a burst and have had to use the following as a workaround. Has anyone else found the same, or perhaps I have set something up incorrectly. Massive thanks for providing this asset Open Source.

    Code (CSharp):
    1. GameObject ParticlesGameObject;
    2. ParticleSystem Particles;
    3.  
    4. public void Burst()
    5. {
    6.     if (!ParticlesGameObject.activeInHierarchy)
    7.     {
    8.         ParticlesGameObject.SetActive(true);
    9.     }
    10.     else
    11.     {
    12.         Particles.Stop();
    13.         Particles.Play();
    14.     }
    15. }
    I should be able to have the following...

    Code (CSharp):
    1. ParticleSystem Particles;
    2.  
    3. public void Burst()
    4. {
    5.     Particles.Stop();
    6.     Particles.Play();
    7. }
     
    Last edited: Oct 31, 2018
    Jao_Preto likes this.
  20. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    In the code, one can find this:

    Code (CSharp):
    1. private ParticleSystem.TextureSheetAnimationModule textureSheetAnimation;
    2. private ParticleSystemRenderer pRenderer;
    Plus a large section dedicated to the use of these elements. It seems the script was actually meant to work with texture sheet animation and the renderer block, but currently does not.
     
  21. FunRobDev

    FunRobDev

    Joined:
    Jun 3, 2017
    Posts:
    11
    If you ever wonder why the TextureSheetAnimation / RandomRow checkbox doesn't work, then the problem is in these lines:
    In lines #156-158 there is this part:
    Code (CSharp):
    1. // if (textureSheetAnimation.useRandomRow) { // FIXME - is this handled internally by rowIndex?
    2. // row = Random.Range(0, textureSheetAnimation.numTilesY, using: particle.randomSeed);
    3. // }
    Here is my fix:
    Code (CSharp):
    1.  
    2. if (_textureSheetAnimation.useRandomRow) row = (int)( particle.randomSeed % _textureSheetAnimation.numTilesY);
    3.  
    God bless
     
    Last edited: Dec 20, 2018
  22. FunRobDev

    FunRobDev

    Joined:
    Jun 3, 2017
    Posts:
    11
    The bug is in line #167:
    Code (CSharp):
    1. particleUV.y = Mathf.FloorToInt(frame / _textureSheetAnimation.numTilesX) * _textureSheedAnimationFrameSize.y;
    You can fix it replacing line #167 to this:
    Code (CSharp):
    1. particleUV.y = 1 - (int)(1 + frame / _textureSheetAnimation.numTilesX) * _textureSheedAnimationFrameSize.y;
     
  23. anthonyk2

    anthonyk2

    Joined:
    Sep 18, 2012
    Posts:
    47
    I can't get it to work on Windows builds using any shaders provided from the UI Extensions/Particles/ folder. Nothing is rendered. Any idea ?

    Edit : the other solution from @Rock360 solved the issue !
     
    Last edited: Jan 17, 2019
  24. StrongCube

    StrongCube

    Joined:
    Nov 22, 2016
    Posts:
    50
  25. fanand20

    fanand20

    Joined:
    Jan 29, 2018
    Posts:
    15
    why It doesn't work for me?
     
  26. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Ok, found at lines 213-215 in current script, but why did you put an underscore before textureSheetAnimation?
    Made the edit. No change at all. UIPS still does not interact with the TextureSheetAnimation block module. That block only works with the Renderer module. The Renderer is useless in Overlay mode.
     
  27. saurya03

    saurya03

    Joined:
    Feb 23, 2019
    Posts:
    4
    NullValueException: Parameter name: Shader
    in Android Build, I have added applied the Build Settings too for default shader.
    Can anyone help me with how to make it work?
     
  28. awesomepiaDev

    awesomepiaDev

    Joined:
    Oct 5, 2018
    Posts:
    3
    awesome!!!!
     
  29. Nattygolden

    Nattygolden

    Joined:
    Apr 17, 2014
    Posts:
    3
    works perfectly, thanks
     
  30. afshin_a_1

    afshin_a_1

    Joined:
    Apr 26, 2015
    Posts:
    52
    hi @glennpow @SimonDarksideJ @Zarlang @pevicentini
    tnx glennpow. i test this solution and it works on editor scene view and game view. but i build my project for Android and it's like there's no particle even. no particles rendering. what should i do?
    i used @Zarlang uploaded folder, with script and shaders included.
     
  31. YoungXi

    YoungXi

    Joined:
    Jun 5, 2013
    Posts:
    63
    Well... This component rebuilds itself every frame... I'd suggest using another camera to render those particles on to a render texture, and using a RawImage component to render that again, worthy trade off.
     
  32. orrinjones

    orrinjones

    Joined:
    Jan 14, 2017
    Posts:
    8
    Thank you very much for sharing this
     
  33. Apollych

    Apollych

    Joined:
    Oct 7, 2019
    Posts:
    8
    About using the sprite in the UI particles.
    1) I just created a material with Mobile/Particles shader
    2) Set sprite to the material
    3) Set this material to Material property of UI Particle System (particles disappeared at all)
    4) Set the shader property of the material to UI/Default - sprites now visible! Profit )
     
  34. Jao_Preto

    Jao_Preto

    Joined:
    Apr 11, 2019
    Posts:
    2


    Thank you, your post saved my life. I was having problem with ".play()".
     
  35. ertbaran

    ertbaran

    Joined:
    Feb 22, 2019
    Posts:
    11
    Dude, Really thanks so much from 2020.
     
  36. johanhelsing_attensi

    johanhelsing_attensi

    Joined:
    Mar 24, 2020
    Posts:
    8
    Since we're necro-bumping (sort-of). This seems like a better solution: https://github.com/mob-sakai/ParticleEffectForUGUI

    According to its readme, these are the disadvantages of OP's approach:

    - Adjustment is difficult.
    - Requires UI shaders.
    - Difficult to adjust scale.
    - Force hierarchy scalling.
    - Simulation results are incorrect.
    - Trail, rotation of transform, time scaling are not supported.
    - Generate heavy GC every frame.
     
    xVergilx and IggyZuk like this.
  37. ATLGAN

    ATLGAN

    Joined:
    Oct 15, 2017
    Posts:
    12
    I can't play the particle system on runtime via script because active particleSystem.simulate.
     
  38. MODev

    MODev

    Joined:
    Jul 30, 2013
    Posts:
    229
    @johanhelsing_attensi probably it's always like that. Especially in "free" solutions, where community does not spend that much time to solve certain problems (as no one pay for spending time over this). If you take paid one (sometimes for price of single dinner/lunch) you have less problems and in many cases better workflow but you need to pay for them.
     
  39. johanhelsing_attensi

    johanhelsing_attensi

    Joined:
    Mar 24, 2020
    Posts:
    8
    Well, when it comes to libraries/utilities, I often find that popular open source libraries tend to have a lot less issues than most asset store packages.

    https://github.com/mob-sakai/ParticleEffectForUGUI seems like a popular and maintained project that a lot of people probably depend upon, which is why I think it's probably a better choice than several years old forum copy-pasta... which is why I wanted to give a heads up in case someone stumbles upon this thread and thinks it's still a good solution.
     
  40. ATLGAN

    ATLGAN

    Joined:
    Oct 15, 2017
    Posts:
    12
    This is not possible because 1$ = 8TL is in the Turkey!!
     
  41. Umarji

    Umarji

    Joined:
    Sep 1, 2018
    Posts:
    1
    @SimonDarksideJ or anyone who is able to overcome this issue, I'm still facing the second issue you mentioned about Particle object always rendering behind image. How can I fix that? Am I missing something? Any thoughts. Currently using 2019.4 Unity
     
    Last edited: Jun 15, 2021
  42. deLord

    deLord

    Joined:
    Oct 11, 2014
    Posts:
    306
    I tried it again and it kinda works, but I get this result:
    ps.png

    Since I am a noob with shaders/materials etc, maybe someone can help me? Unity 2019.4.18f1
     
  43. metinevren

    metinevren

    Joined:
    May 17, 2014
    Posts:
    30
    It says "The script don't inherit a native class that can manage a script."?
     
  44. deLord

    deLord

    Joined:
    Oct 11, 2014
    Posts:
    306
    if that was a question for me, I don't see this error anywhere
     
  45. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I can't seem to get the particles to render on iOS. it's working in editor... I've included the hidden shader in the project settings as well, no luck.
     
  46. MichalMarsalek

    MichalMarsalek

    Joined:
    Nov 11, 2012
    Posts:
    14
    I'm having the same issue, have you found any solution?
     
  47. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I found a shader with some errors when running on iOS so it might be a similar problem. look at the xCode log output for shader related issues.

    I also found newer unity versions are better at revealing shader errors so it might be worth opening the project in a later or even beta unity just so check if that reveals any errors.
     
  48. SIJoshua

    SIJoshua

    Joined:
    May 5, 2022
    Posts:
    1
    Is it expected behaviour from this system that the particles cannot have a 3D size? Changing the Y value for the start size for instance, has no effect.
     
  49. mwieliczuk

    mwieliczuk

    Joined:
    Mar 28, 2022
    Posts:
    2
    The UIParticleSystem script works with your shaders and I was wondering if it could be written in a shader graph. I have information about shape and alpha but I don't have color information. It's always dark blue. Do you know if it is possible to create a graph shader that would work with this script?
    upload_2023-1-26_14-22-12.png
    There is my shader.
    A custom function that I used is a simple in-out function where I tried to add pragmas.
    Without the custom function shader works in the same way.
    @SimonDarksideJ
     
    Last edited: Jan 26, 2023
    SimonDarksideJ likes this.
  50. nicolasc_unity974

    nicolasc_unity974

    Joined:
    Sep 21, 2022
    Posts:
    7
    does anyone know if there is a similar script or different one that focus on making this idea to work with trail in particle system?