Skip to content

Instantly share code, notes, and snippets.

@cosmogonies
Last active March 8, 2022 14:36
Show Gist options
  • Save cosmogonies/4ed7ac8d85f8f69cf2e7 to your computer and use it in GitHub Desktop.
Save cosmogonies/4ed7ac8d85f8f69cf2e7 to your computer and use it in GitHub Desktop.
Callback on Apply Prefab (Unity)
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
internal class PrefabExtension
{
static PrefabExtension()
{
UnityEditor.PrefabUtility.prefabInstanceUpdated += OnPrefabInstanceUpdate;
}
static void OnPrefabInstanceUpdate(GameObject instance)
{
UnityEngine.Debug.Log("[Callback] Prefab.Apply on instance named :" + instance.name);
GameObject prefab = UnityEditor.PrefabUtility.GetPrefabParent(instance) as GameObject;
string prefabPath = AssetDatabase.GetAssetPath(prefab);
UnityEngine.Debug.Log("@Prefab originPath="+prefabPath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment