Provides information about package registration changes that occur during Package Manager operations.
This class contains details about packages being added, removed, or updated in the project.
Remarks
changedFrom
and changedTo
collections must be iterated together to maintain package correspondence. They are guaranteed to match in length and ordering.PackageRegistrationEventArgs
might contain empty collections if no packages were added, removed, or changed.using System; using UnityEditor.PackageManager; using UnityEngine;
[ExecuteInEditMode] public class PackageRegistrationExample: MonoBehaviour { void Start() { SubscribeToPackageEvents(); }
void OnDestroy() { Cleanup(); }
void SubscribeToPackageEvents() { // Subscribe to the event before packages change Debug.Log("Subscribing to registeringPackages"); Events.registeringPackages += OnPackagesRegistering; }
void OnPackagesRegistering(PackageRegistrationEventArgs args) { // Log added packages foreach (var package in args.added) { Debug.Log($"Adding package: {package.displayName} ({package.version})"); }
// Log removed packages foreach (var package in args.removed) { Debug.Log($"Removing package: {package.displayName} ({package.version})"); }
// Log package updates using var changes = args.changedFrom.GetEnumerator(); using var targets = args.changedTo.GetEnumerator(); while (changes.MoveNext() && targets.MoveNext()) { var oldPackage = changes.Current; var newPackage = targets.Current; Debug.Log($"Updating {oldPackage?.displayName} from {oldPackage?.version} to {newPackage?.version}"); } }
void Cleanup() { // Unsubscribe from the event when finished Debug.Log("Unsubscribing to registeringPackages"); Events.registeringPackages -= OnPackagesRegistering; } }
Related information
Property | Description |
---|---|
added | A collection of PackageInfo entries to add during the Package Manager registration process. |
changedFrom | A collection of PackageInfo entries describing packages to be overridden by another version during the Package Manager registration process. |
changedTo | A collection of PackageInfo entries describing packages that will override a previously registered version during the Package Manager registration process. |
removed | A collection of PackageInfo entries to remove during the Package Manager registration process. |