# High frequency of UnityEditor.SetDirty calls

**URL:** <https://qa.fmod.com/t/high-frequency-of-unityeditor-setdirty-calls/15036>\
**Category:** Unity\
**Created:** [September 9, 2019, 9:26pm UTC](https://qa.fmod.com/t/high-frequency-of-unityeditor-setdirty-calls/15036 "2019-09-09T21:26:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ttsmike](https://avatars.discourse-cdn.com/v4/letter/t/f07891/32.png) [@ttsmike](https://qa.fmod.com/u/ttsmike)\
**Post date:** [September 9, 2019, 9:26pm UTC](https://qa.fmod.com/t/high-frequency-of-unityeditor-setdirty-calls/15036/1 "2019-09-09T21:26:27Z")

</div>

Hello again. I briefly mentioned a lower priority issue in this thread ([SourceBankPathUnformatted destroyed by SourceBankPathRelative](https://qa.fmod.com/t/sourcebankpathunformatted-destroyed-by-sourcebankpathrelative/15035)).

Long story short, one of our engineers wasn’t particularly happy with the frequency of calls to `EditorUtility.SetDirty` inside `EventManager`'s `OnCacheChange` function, given that the data hasn’t _actually_ changed.

They asked me to recommend a change we made, where we would check the banks, and to only `SetDirty` and `Repaint` when an _actual_ change had occurred.

```auto
        static List<string> tempMasterBanks = new List<string>();
        static List<string> tempBanks = new List<string>();

        static void OnCacheChange()
        {
            var settings = Settings.Instance;

            bool hasChanged = false;

            tempMasterBanks.Clear();
            foreach (EditorBankRef bankRef in eventCache.MasterBanks)
            {
                tempMasterBanks.Add(bankRef.Name);
            }

            if (!CompareLists(tempMasterBanks, settings.MasterBanks))
            {
                settings.MasterBanks.Clear();
                settings.MasterBanks.AddRange(tempMasterBanks);
                hasChanged = true;
            }

            tempBanks.Clear();
            foreach (var bankRef in eventCache.EditorBanks)
            {
                if (!eventCache.MasterBanks.Contains(bankRef) &&
                    !eventCache.StringsBanks.Contains(bankRef))
                {
                    tempBanks.Add(bankRef.Name);
                }
            }
            tempBanks.Sort((a, b) => string.Compare(a, b, StringComparison.CurrentCultureIgnoreCase));

            if (!CompareLists(tempBanks, settings.Banks))
            {
                settings.Banks.Clear();
                settings.Banks.AddRange(tempBanks);
                hasChanged = true;
            }

            if (hasChanged)
            {
                EditorUtility.SetDirty(settings);
                EventBrowser.RepaintEventBrowser();
            }
        }

```

Unity `2019.1.14f1` and FMOD Unity Integration `2.00.04`.

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [September 17, 2019, 1:19am UTC](https://qa.fmod.com/t/high-frequency-of-unityeditor-setdirty-calls/15036/2 "2019-09-17T01:19:58Z")

</div>

Thanks for the feedback, that does seem like a good change.

I’ll make a task to add this in an upcoming release.
