Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

(LWRP) Using 2D Lights in a Particle System Emitter

Discussion in 'Universal Render Pipeline' started by Vento313, Jul 30, 2019.

  1. Vento313

    Vento313

    Joined:
    Feb 27, 2016
    Posts:
    5
    Is that possible? The Particle System won't allow me to use a 2D light in its emitter. Am I missing something or is this not implemented yet?
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    Hey, thanks for raising this.

    It's not currently supported, but we are discussing how feasible it would be to support in the future.
     
    AlterHaudegen likes this.
  3. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Hi! 2D lights are regular MonoBehaviours rather than real Unity lights, therefore the Lights module of the Particle System can't support 2D lights.

    That being said, we're interested in finding another way to hook up 2D lights to particle emitters, so please keep telling us about your use cases and maybe we'll have something for you in the future.
     
    Kane_da, Bvenjamin and AlterHaudegen like this.
  4. ltlejeune

    ltlejeune

    Joined:
    Aug 6, 2019
    Posts:
    24
    Hey all,

    I'm in the same situation as the early publisher, I find LWRP super for my case (2D game, high level view on a map), but I'm currently using particle system to simulate fireflies, with the super nice noise, emission and lights... making LWRP for now not an option :/

    Is there any forecast on next Unity releases proposing this feature ?
     
  5. Leonxweb

    Leonxweb

    Joined:
    Feb 23, 2018
    Posts:
    1
    Hey, Is it possible to make a partial system through shaders and thereby use 2D light?
     
  6. AlterHaudegen

    AlterHaudegen

    Joined:
    Jul 8, 2013
    Posts:
    28
    I'm using particles systems (due to their flexibility) for projectiles, explosions, item pickups and of course vfx. Yes, 2D lights would be fantastic!
     
    richardkettlewell likes this.
  7. hungteoh123

    hungteoh123

    Joined:
    Feb 15, 2019
    Posts:
    1
    Hello is there any alternative to implement this ? Currently stuck at here :(
     
    Kane_da and DevilCult like this.
  8. m-pire

    m-pire

    Joined:
    Jul 12, 2019
    Posts:
    6
    I also would be really interessted in having 2D light particles !
     
  9. Leobizaz

    Leobizaz

    Joined:
    Aug 31, 2019
    Posts:
    2
    Please add 2D lights to particles
     
    TommySkunk likes this.
  10. Enrique48k

    Enrique48k

    Joined:
    Apr 30, 2019
    Posts:
    10
    I am also very interested. Please, it would be great if you could implement it.
     
  11. MrPaparoz

    MrPaparoz

    Joined:
    Apr 14, 2018
    Posts:
    157
    Well, VFX Graph with Sprite Lit Output would be cool.
     
  12. Kane_da

    Kane_da

    Joined:
    Feb 16, 2019
    Posts:
    1
    +1 - I'm also using Particle Systems for various effects in an otherwise strictly 2D game, and I'd love to be able to use 2D lights on particles in 2D URP. In fact, I came to this thread when searching how to do it. ;)
     
  13. DatThax

    DatThax

    Joined:
    Jun 18, 2019
    Posts:
    10
    I could really use 2D lights with particles to create glowing sparks in my 2D game.
     
  14. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    Hey all, could a script like the one attached help you out with this?
    It simply instantiates GameObjects and attaches them to particles.

    It would benefit from some more work to set light properties based on particle colors/sizes, like we have in the Lights Module.
     

    Attached Files:

  15. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    It is works, but only in the beginning, then I have this his error:

    Code (CSharp):
    1. MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    2. Your script should either check if it is null or you should not destroy the object.
    3. AttachGameObjectsToParticles.LateUpdate () (at Assets/Game/Scripts/Misc/AttachGameObjectsToParticles.cs:36)
     
  16. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    That's odd - the script never deletes those GameObjects. I wonder how that happened..
     
  17. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    I got that, I just have "Destroy after" script on my prefab. Everything fine now :)
     
    richardkettlewell likes this.
  18. emehlos

    emehlos

    Joined:
    Mar 27, 2017
    Posts:
    1
    Would love it is 2D Lights were supported for particles as well, thanks.
     
    russellnadin and TommySkunk like this.
  19. marcola_gt

    marcola_gt

    Joined:
    Apr 19, 2017
    Posts:
    6
    Hey! I'm so sad about this... I was trying to figure out why my particle system doesn't accept my 2D light... Now I know...
    Please do us this huge favor and implement this, guys...
     
    russellnadin likes this.
  20. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
  21. Rygielsiu

    Rygielsiu

    Joined:
    Mar 3, 2020
    Posts:
    2
    Hiya!
    The script helps a lot, thank you!
    I have attached 2D lights to it but now I am working on fading the light in and out to be a bit more realistic. At the moment it looks like the light just all of a sudden shows up and lights up the area around it. I have managed to get a script working to do the fade in and out by attaching a script to a 2D Light prefab and running a coroutine on those lights. The problem I am facing is that now some of the particles, all of a sudden jump their position somewhere else within the are of the Particle System and it looks again as if more intense light source was showing up in the scene. Any ideas how to tackle that?
     
  22. Nutcracker903

    Nutcracker903

    Joined:
    Mar 2, 2020
    Posts:
    1
    DannyTheBiBoi likes this.
  23. mehdisaidibac

    mehdisaidibac

    Joined:
    Apr 15, 2018
    Posts:
    1
    Maybe we can give the sprite's material an emission map with 2D shader graphs, then attach a 2d light to the particle system GameObject, it might look as if the particles are emitting light. Maybe even change the light's color based on particles color in real-time. Didn't try it yet though.
     
    MrPaparoz likes this.
  24. MrPaparoz

    MrPaparoz

    Joined:
    Apr 14, 2018
    Posts:
    157
    actually other than particles emission slot is necessary for some other distinctions in lit shader.
     
  25. Orelien

    Orelien

    Joined:
    Jul 29, 2019
    Posts:
    1
    Worked perfectly for me thanks!
     
  26. jhalesy

    jhalesy

    Joined:
    Mar 21, 2020
    Posts:
    2
    Hi, just cooked up another method. Create another sorting layer for your particle effect then have a 2D global light which only affects the layer with the particle effect on works very well.
     
    richardkettlewell likes this.
  27. DatThax

    DatThax

    Joined:
    Jun 18, 2019
    Posts:
    10
    But does that illuminate sprites below the particles? I think it wouldn't, right?
     
  28. joan_stark

    joan_stark

    Joined:
    Jul 24, 2018
    Posts:
    39
    I've worked on changing the size of the light to match particle size.

    Just add this line inside the "for" in first place.
    Maybe you have to play a little bit with the radius or size of the light in the prefab, but it will work.

    Code (CSharp):
    1. m_Instances[i].transform.localScale = new Vector3(m_Particles[i].startSize, m_Particles[i].startSize, m_Particles[i].startSize)
    Nothing complex, just changing scale to particle size.
    I've tried doing this only once x particle/light but couldn't find any way.
     
    ryoma1492 likes this.
  29. Black_Pawn

    Black_Pawn

    Joined:
    Apr 30, 2020
    Posts:
    1
    richardkettlewell likes this.
  30. jhalesy

    jhalesy

    Joined:
    Mar 21, 2020
    Posts:
    2
    No, it wouldn't.
     
  31. ryoma1492

    ryoma1492

    Joined:
    Jul 16, 2020
    Posts:
    11
    this was a wonderful addition onit's own... it DOES seem to react more like i would like ONLY when the particles are set to "World" instead of local (scale and distance were issues before i checked this... so i traded some performance for not having to manually change the scale and distance for each instance i had)


    Thanks So Much!
     
    richardkettlewell likes this.
  32. Bogdar

    Bogdar

    Joined:
    Sep 5, 2020
    Posts:
    1
    Wonderful script ! So it was that easy to implement. It was very easy to tweak it so that it reflects the original module as well. Thanks !
     
    richardkettlewell likes this.
  33. Benjamin_Lehmann

    Benjamin_Lehmann

    Joined:
    Nov 30, 2019
    Posts:
    8
    +1 would really appreciate having 2d lights work with particle systems. Would feel so intuative and have so many creative applications. I'll use your script for now, but I always feel sort of uncomfortable with bespoke solutions - I like it when it feels like you're working with the engine in the way that it's designed. Peace and love.
     
    MrPaparoz and richardkettlewell like this.
  34. JonX7

    JonX7

    Joined:
    Jul 4, 2016
    Posts:
    4
    +1 I'm creating a particle system in a 2D game that is supposed to simulate sparks coming from a damaged panel in a dark room. The effect would be amazing if each particle could render lighting to the right layers!
     
    awsapps and richardkettlewell like this.
  35. wind_of_daybreak

    wind_of_daybreak

    Joined:
    Feb 4, 2021
    Posts:
    2
    +1 2D light for particle system pls
     
  36. aromana

    aromana

    Joined:
    Nov 11, 2018
    Posts:
    137
    Just adding another +1 here for being able to use 2D lights in a particle system. If Unity is serious about Project Tiny and being a first-class authoring environment for 2D games, this seems like a pretty important feature request :)
     
  37. thereadypunk

    thereadypunk

    Joined:
    Mar 16, 2020
    Posts:
    2
    Thanks! It works perfectly for my muzzle flash.
     
    richardkettlewell likes this.
  38. HofiOne

    HofiOne

    Joined:
    Apr 19, 2021
    Posts:
    68
    +1 for support of 2D lights in the Lights module of the Particle System!!!
    Pls !!!
     
  39. Wrenzo

    Wrenzo

    Joined:
    Apr 18, 2020
    Posts:
    1
    I also encountered this problem. But what I did is the following:
    *make a round sprite that gradients outward with transparent background(this is what I need on my project but you can make whatever)
    *create a new lit material using this sprite
    *let your particle system use this material
    *move the particle system to its own sorting layer
    *create a new 2D global light for this layer and make sure no other global lights affect this layer

    This way, you can manipulate the particles' color, alpha, etc. and it should work as intended(atleast for me). I'm new to unity and this is just a simple(and incomplete) work around I came up with after a week of agony.
     
    Last edited: Nov 15, 2021
  40. R-A-V-S-O

    R-A-V-S-O

    Joined:
    Oct 22, 2014
    Posts:
    5
    I've been playing around with this particle light script myself, and realized its possible to tweak intensity based on a particle's remaining lifetime, it sort of works in regards that a particle's illumination now fades as the lifetime ends, but when a new particle is instantiated the light suddenly appears at full intensity making it a bit jumpy.

    Just add this line in after the if/else worldspace check:
    Code (CSharp):
    1. m_Instances[i].GetComponent<UnityEngine.Experimental.Rendering.Universal.Light2D>().intensity = (m_Particles[i].remainingLifetime / intensityDivider);
    intensityDivider in this case is merely a value I use to dampen excess intensity to avoid having extremely bright particles, can be replaced for any float value desired.

    And should give you this ok-ish fading light effect that works for firefly types of particles:

    light test.png
     
  41. Dragorkhan

    Dragorkhan

    Joined:
    Jul 30, 2019
    Posts:
    1
    I dont know if this is still an issue for some of you or if you want another way to add light to your PS. I figured out that you can do it by using HDR as the color for the material. Then you can tweak the intensity of the color and apply bloom to your scene by adding a global volume.

    upload_2022-1-31_22-7-59.png
     
    ranjansikand, Krusavchik and Naver78 like this.
  42. BmanStudio

    BmanStudio

    Joined:
    Aug 7, 2019
    Posts:
    1
    Still needed lol
     
  43. MidievalMan

    MidievalMan

    Joined:
    Jul 1, 2020
    Posts:
    4
    The script isn't working for me somehow, it isn't instantiating any GameObjects at all. Anyone else have a similar problem and got it to work?
     
  44. HaraldNordgren

    HaraldNordgren

    Joined:
    Oct 10, 2023
    Posts:
    1
    Thanks!

    Is this still the preferred way to do it in 2023?
     
    richardkettlewell likes this.
  45. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    Yes. Honestly, it always will be. We aren't working on new stuff for the Particle System, so I don't think it will get proper support for the package-based 2D lights.