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

Bug Set light's custom shadow bias properties via script

Discussion in 'Scripting' started by allworknoplay, Oct 28, 2021.

  1. allworknoplay

    allworknoplay

    Joined:
    Mar 5, 2015
    Posts:
    21
    I'm using Unity 2021.1.19f1 and URP 11.0.

    Realtime lights have a shadows property drawer in the editor that says "Bias: Use Pipeline Settings". I want to change this to "Custom" via script and interact with the shadow bias properties therin, but they don't seem to be accessible.

    Screenshots and commentary of everything at this imgur thread here: https://imgur.com/a/5giB0JQ

    The script reference (https://docs.unity3d.com/ScriptReference/Light.html) clearly shows these properties available, but setting them via script does not change the pipeline/vs custom settings drawer, and my values don't take effect.

    I went into the debug inspector to see what actual property changed when I toggled the drawer -- it's the "Resolution" property, which corresponds to the `shadowResolution` property listed in the docs, a `Rendering.LightShadowResolution` enum value. However, the change is that the dropdown is now blank.

    Again, check the imgur thread above.

    I made two light prefabs that were identical except for the pipeline/custom setting, and opened the serialized versions. The pipeline prefabs resolution value was `-1`, and the custom one was `128`. For an enum with four values. Cool cool cool.

    I tried just setting it in my script to 128, but it pretty clearly didn't work; the actual property the light uses is a member of a private struct or class, and the setter clearly expects the actual enum type and validates its values if I try to coerce it. I also dug up Unity's light editor c# code here (though it's from 2020.2), and it seems to match that.

    So: am I doing something wrong or missing some way to do this, or are these documented properties not actually accessible via script?

    Thanks in advance!

    PS, please don't be one of those people who tells me to just do it in the editor or demands to know why I need to do this. I can and will if I need, but I control all my real-time lighting via script, so I'd rather not, and the docs seem like I ought to be able to do this. Thanks!