Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

PanelRenderer.RegisterUIReloadCallback

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public void RegisterUIReloadCallback(UIReloadCallback callback);

Parameters

Parameter Description
callback The callback to register.

Description

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.


Declaration

public void RegisterUIReloadCallback(VersionedUIReloadCallback callback);

Parameters

Parameter Description
callback The callback to register.

Description

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 } }