Question about changing the light falloff-intensity via script

Hey guys,

I am currently trying to get a script to work that randomly changes the light falloff, im pretty new to unity, so i might be missing an obvious solution here.

I tried it with this line of code:
light.falloffIntensity = falloffintensity;

light is already set as the correct 2D light, im also changing the intensity in this script with falloff.intensity and that works just fine.

The error i am getting is this one:

The property UnityEngine.Experimental.Rendering.Universal.Lights2D.falloffIntensity has no setter.

I couldnt really find anything searching the web, maybe one of you can help.
Thank you! :slight_smile:

1 Like

I know it’s been a year since this has been asked, but I thought I’d share a possible solution. It’s not the best but you can use reflection to skirt the issue:

private static FieldInfo m_FalloffField =  typeof( Light2D ).GetField( "m_FalloffIntensity", BindingFlags.NonPublic | BindingFlags.Instance );

private Light2D m_Light;

// ...

public void SetFalloff(float falloff)
{
    m_FalloffField.SetValue( m_Light, falloff );
}

I used Light2D but you can extend this idea to other scripts. Just look into the source file and find the private field you want to set.

2 Likes

Thank you.