How to get notification of internal change in Dictionary?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By goshot

How do you get notification that the contents of a Dictionary instance changed? Specifically, in a tool script where the user edits the Dictionary in the Inspector?

It’s possible to use setget on a Dictonary variable and implement the setter function to emit a signal, but that only captures when the Dictionary variable is set to a whole Dictionary instance. It does not capture when the contents of the Dictionary are modified.

It doesn’t look like there are signals for when Dictionaries are changed. So it looks like you’ll have to do it some other way.

One way to monitor a Dictionary is to check how many keys the Dictionary has. A change in the number of keys indicates that a change has happened in the entire Dictionary. If you only need to monitor a few keys, then check the size of the values. If the values changed in size, then the Dictionary changed. If you really need to keep track of them, check the hashes of the values. If they change, then the Dictionary has changed.

Ertain | 2019-09-08 23:14