guycalledfrank / bakery-issues

Bug tracker for Bakery
4 stars 0 forks source link

explicit initialization > relying on lifecycle #94

Closed laurentopia closed 3 years ago

laurentopia commented 3 years ago

this is better because if we reuse receiver for something that bypasses lifecycle of physics trigger then this isn't initialized image

laurentopia commented 3 years ago

it's in BakeryVolumeReceiver

guycalledfrank commented 3 years ago

I kept BakeryVolumeReceiver simple so it's easy to understand and modify. Not sure if I understood what problem it solves. Awake still does the same thing, but you additionally execute it in SetPropertyBlock in case it was called before Awake? In this case we can probably just check for renderers == null, e.g.:

    public void SetPropertyBlock(MaterialPropertyBlock mb)
    {
        if (renderers == null) renderers = GetComponentsInChildren<Renderer>() as Renderer[];
        for(int i=0; i<renderers.Length; i++)
        {
            renderers[i].SetPropertyBlock(mb);
        }
        current = mb;
    }

No need to apply empty property blocks before applying actual property blocks.

laurentopia commented 3 years ago

ok and test renderers in awake in case SetPropertyBlock was called before it // Cache renderers affected by volumes void Awake() { if (renderers==null) renderers = GetComponentsInChildren<Renderer>(); if (forceUsage) { // HDRP can sometimes (?) fail to use globally set volumes when SRP batching is enabled, so disable it for this object. SetPropertyBlock(new MaterialPropertyBlock()); } }

guycalledfrank commented 3 years ago

Added: https://github.com/guycalledfrank/bakery-csharp/commit/b2499932bd39d60e40112676017e459ad4029b1f