I need to change the sprite of a 2D light in a script. I need to create a Light2D with a light type Sprite and then in the script change the sprite to whatever I need. I looked at the object and all I can see that is is a sprite is lightCookieSprite that is only get-able.
By editing your temporary version of Light2D.cs you can work around this; I’m not sure why it’s not settable, Light2D itself already supports the sprite being changed in other parts of the code from what it seems.
You’ll need to change line 212 to the following:
public Sprite lightCookieSprite
{
get { return m_LightCookieSprite;}
set { m_LightCookieSprite = value; }
}
I’m not sure how safe or stable this is, but it works decently enough until Unity updates the field to be officially settable.
Can Unity please take care of this? This sound trivial to fix but it would save so much pain… fields visible in the inspector should be changeable by code.
You can access the private backing field for the ‘LightCookieSprite’ property and set that. This applies for any other property that doesn’t have a setter.