Hi,
I am using URP as 2D renderer and everything is ok: I can create 2d lights and they work very nice using normalmaps during design time, but when I click on “Run”, the property gets disabled and can’t be changed via scripts as it is a read only property:
private
UnityEngine.Experimental.Rendering.Universal.Light2D
_myLight;
_myLight = transform.parent.GetComponentInChildren();
_myLight.normalMapQuality= …
Please, somebody help me!!
Aaaaahm… I dunno if it is about a bug or not, but I found something at:
C:\Program Files\Unity\Hub\Editor\2021.1.3f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.render-pipelines.universal\Runtime\2D\Light2D.cs
There’s a boolean serialized field that is set to false:
[SerializeField] bool m_UseNormalMap = false; // This is now deprecated. Keep it here for backwards compatibility.
And then, in Awake() we have this:
*if (!m_UseNormalMap && m_NormalMapQuality !=
NormalMapQuality.Disabled)
m_NormalMapQuality = NormalMapQuality.Disabled;*
So we have that NormalMapQuality is always set to Disabled. As I said, I dunno if it is a bug, but I found no solution anywhere, no answers in forums and I needed this working, so I changed the initial value from false to true in the Light2D.cs file (I had to grant write permissions to do it), I started my project and I replaced all my spot 2d lights with new instances. Result: working.
I think an easier solution based on @YupiNawate suggestion is to set the value for all the m_UseNormalMap
fields in the scene file (.unity file) to 1 once.
My answer to this was to fix it in the editor for Light2d, so that if you set a value for the quality OTHER than disabled it changes m_UseNormalMap to true. Then things get saved properly and not reset on load.
This is the function that handles the Normal Map settings. I added the one line marked.
void DrawNormalMapGroup()
{
CoreEditorUtils.DrawSplitter(false);
m_NormalMapsSettingsFoldout.value = CoreEditorUtils.DrawHeaderFoldout(Styles.normalMapsSettingsFoldout, m_NormalMapsSettingsFoldout.value);
if (m_NormalMapsSettingsFoldout.value)
{
EditorGUILayout.PropertyField(m_NormalMapQuality, Styles.generalNormalMapLightQuality);
EditorGUI.BeginDisabledGroup(m_NormalMapQuality.intValue == (int)Light2D.NormalMapQuality.Disabled);
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_NormalMapZDistance, Styles.generalNormalMapZDistance);
if (EditorGUI.EndChangeCheck())
m_NormalMapZDistance.floatValue = Mathf.Max(0.0f, m_NormalMapZDistance.floatValue);
//// Add this line to make it preserve the values you set
m_UseNormalMap.boolValue = (m_NormalMapQuality.intValue != (int)Light2D.NormalMapQuality.Disabled);
//// End Changes
EditorGUI.EndDisabledGroup();
}
}