guycalledfrank / bakery-issues

Bug tracker for Bakery
4 stars 0 forks source link

Real Time Preview only updates when directly changing a Bakery Light component #48

Closed Zurigan closed 3 years ago

Zurigan commented 3 years ago

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:

image

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?

guycalledfrank commented 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).

Zurigan commented 3 years ago

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.

guycalledfrank commented 3 years ago

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

Zurigan commented 3 years ago

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.