Subscribe to Setting Changes

The omni.kit.app extension contains the SettingChangeSubscription class that allows you to subscribe a callback for when a setting value changes. This is useful for when you want to allow other parts of the app to interactively change the behavior of your extension. This snippet shows how to subscribe to settings value changes and provide a callback function to execute code whenever a setting changes.

Note

Each extension puts settings in /ext/[ext_name]/ to not conflict with settings from other extensions. Extensions should also list their settings in their extension.toml to make the settings discoverable to users and developers.

import carb.settings
import omni.kit.app

settings = carb.settings.get_settings()

def on_change(value, change_type: carb.settings.ChangeEventType):
    print(value, change_type)

# subscribe to value changes, returned object is subscription holder. To unsubscribe - destroy it.
subscription1 = omni.kit.app.SettingChangeSubscription("/exts/your.ext.name/test/test/value", on_change)

settings.set("/exts/your.ext.name/test/test/value", 23)
settings.set("/exts/your.ext.name/test/test/value", "fall")
settings.set("/exts/your.ext.name/test/test/value", None)
settings.set("/exts/your.ext.name/test/test/value", 89)

# release the subscription reference to stop receiving callbacks.
subscription1 = None
# no more notifications
settings.set("/exts/your.ext.name/test/test/value", 100)