Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

Holder.LifecycleEventHandler

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

Description

Occurs when the Adaptive Performance instance is created or destroyed during lifecycle changes.

This event fires automatically when the Holder.Instance property value changes. A LifecycleChangeType.Created event fires when a new IAdaptivePerformance instance is assigned, and a LifecycleChangeType.Destroyed event fires when the instance is set to null.

Subscribe to this event to track when Adaptive Performance becomes available or unavailable. Doing so is useful for managing dependent systems or UI state that relies on Adaptive Performance.

The event fires from the Holder.Instance property setter, so it occurs during Holder.Initialize and Holder.Deinitialize operations.

 using UnityEngine;
 using UnityEngine.AdaptivePerformance;
 
 public class AdaptivePerformanceTracker : MonoBehaviour
 {
     void Start()
     {
         // Subscribe to lifecycle events.
         Holder.LifecycleEventHandler += OnAdaptivePerformanceLifecycle;
     }
 
     void OnDestroy()
     {
         // Unsubscribe to prevent memory leaks.
         Holder.LifecycleEventHandler -= OnAdaptivePerformanceLifecycle;
     }
 
     void OnAdaptivePerformanceLifecycle(IAdaptivePerformance instance, LifecycleChangeType changeType)
     {
         switch (changeType)
         {
             case LifecycleChangeType.Created:
                 Debug.Log("Adaptive Performance is now available.");
                 break;
             case LifecycleChangeType.Destroyed:
                 Debug.Log("Adaptive Performance is no longer available.");
                 break;
         }
     }
 }