Setting "lightCookieSprite" for "Light2D (Experimental)"

The lightCookieSprite variable which is the sprite part of Light2D only has a getter, but not a setter. Because of this, I can’t set the sprite. I tried to change the script, but every time it compiles, it reverts back to how it was before. Is it a way to fix this? I’ve tried to copy the Light2D.cs into my assets and change it there, but it has some weird dependencies (LightUtility is not recognised).

URP is no longer experimental and the cookies have been removed from the lights.

The Sprite light can be used in replacement in URP 11 and above.

https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@12.0/manual/LightTypes.html

I have upgraded to URP 11 on Unity 2021.1.9f1 DX11. The “(experiment)” part of the component has disappeared, but I still can’t set the sprite. The only sprite-variable on Light2D is lightCookieSprite which is “read only”. Upgrading to URP 11 did not fix the problem

Hi!

Are you trying to set the variable in a C# script? There is currently no setter implemented for it. Is there a specific use case that you require, that you cannot achieve with setting the sprite in the property inspector?

I have a need for a setter during runtime. I have the light as a child of a game object that I dynamically set the sprite for and need the sprite for the light to match the parent sprite. Otherwise, the old light stays behind and it wrecks the effect.

I think I can work around it by creating 28 prefabs or attaching 28 children and turning them on/off for now but having a setter would be super handy.

Thank you! Love the renderer!

1 Like

@Welfarecheck Thanks, I will add it to our backlogs.

Just ran into a need myself to adjust the sprite light at runtime to a frame animation. You’re already spending the time to regenerate the sprite mesh every frame and recalculate the bounds in LateUpdate (which seems like a waste to me in particular since you seem to indicate that there is caching there). Please give us public access to setting the sprite light at runtime.

1 Like

bump, this is silly this isn’t possible

@zephyo Which version of Unity are you using? Looks like it wasn’t backported back to 2021.3. It is exposed in Unity 2022.1 or newer. I’ll add the backports later today.

Oh ok thanks so much!!! I’m using latest 2021 LTS