| Parameter | Description |
|---|---|
| callback | The callback to register. |
Registers a callback to be invoked when the UI is reloaded.
This callback will be invoked immediately if the root VisualElement is already initialized, and then every time the UI is reloaded afterwards. Using this method may result in redundant work. It is recommended to use PanelRenderer.RegisterUIReloadCallback instead, which provides a version number so the callback can skip redundant work when the UI has not actually changed.
| Parameter | Description |
|---|---|
| callback | The callback to register. |
Registers a versioned callback to be invoked when the UI is reloaded.
This callback will be invoked immediately if the root VisualElement is already initialized, and then
every time the UI is reloaded afterwards. Use the version parameter to check if the root VisualElement was
actually reloaded since the last time the callback was invoked.
The following example registers a versioned callback to initialize the UI. If the component is repeatedly disabled an
re-enabled, the callback version will stay the same. So, the callback can safely skip the initialization logic after the first time.
using UnityEngine; using UnityEngine.UIElements;
public class LoadUIWithVersion : MonoBehaviour { PanelRenderer m_PanelRenderer; int m_Version = 0;
void OnEnable() { m_PanelRenderer = GetComponent<PanelRenderer>(); m_PanelRenderer.RegisterUIReloadCallback(OnUIReload); }
void OnDisable() { m_PanelRenderer.UnregisterUIReloadCallback(OnUIReload); }
void OnUIReload(PanelRenderer panelRenderer, VisualElement rootElement, int version) { if (version == m_Version) return; // UI already up-to-date, no need to reload
m_Version = version;
// Wire UI here } }