Closed Zurigan closed 3 years ago
BakeryDirectLight.lightsChanged = 1 is exactly what you should do. When the lights are being modified, they signal the preview via OnValidate() method (which is called by the Inspector) and setting these "lightsChanged" values. This way preview doesn't have to scan the whole scene every frame for changes (that would be slow).
You could change Update() in Bakery Lights to look like this:
private float lastKnownIntensity;
void Update()
{
// ...
if (lastKnownIntensity != intensity)
{
lightsChanged = 1;
lastKnownIntensity = intensity;
}
}
That way it'll just work as expected for any idiot like me in the future without having to dig through your code.
I could do that, but I didn't for performance reasons (lots of properties, potentially lots of lights, too much data to compare for no good reason). I don't think there is a major problem adding 1 line to force refresh the preview, added some docs: https://geom.io/bakery/wiki/index.php?title=RTPreview#Scripting
Thanks for adding that to the docs, sure it'll be helpful for someone, someday!
Out of curiosity ... is there a good reason for duplicating the code between all the Bakery Lights? I'd assumed they could/would all inherit from something like BakeryLight.cs
.
I have a simple 'lights manager' component with a bunch of bakery directional lights as children that I want to be able to update/preview all at once. Looks like this:
Updating color or intensity doesn't get reflected in RTP even though the Bakery component values are getting updated. The only way to make this work is to hop in/out of preview which defeats the purpose of it.
Discovered I could hack this to work by including
BakeryDirectLight.lightsChanged = 1;
in my manager every time I change a light ... would be good not to have to do that though.For a cleaner setup maybe change Update() in Bakery Lights to check if values had updated?