Skip to content

Commit 4154023

Browse files
committed
Add handling for repairing referenced prefabs
1 parent 7ddf44f commit 4154023

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Assets/UdonSharp/Editor/UdonSharpEditorManager.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ static void OnChangePlayMode(PlayModeStateChange state)
434434
{
435435
CreateProxyBehaviours(GetAllUdonBehaviours());
436436
}
437+
438+
if (state == PlayModeStateChange.ExitingEditMode)
439+
RunAllUpdates();
437440
}
438441

439442
if (state == PlayModeStateChange.EnteredEditMode)
@@ -547,8 +550,12 @@ static void RepairPrefabProgramAssets(List<UdonBehaviour> dependencyRoots)
547550
HashSet<UnityEngine.Object> dependencies = new HashSet<UnityEngine.Object>();
548551

549552
// Yes, this is not as thorough as AssetDatabase.GetDependencies, it is however much faster and catches the important cases.
553+
// Notably does not gather indirect UdonBehaviour dependencies when one behaviour references a prefab and that prefab references another prefab, mostly because I'm too lazy to handle it at the moment
554+
// Also does not gather any dependencies from Unity component's that reference game objects since that is not something that people should be using for prefab references anyways
550555
foreach (UdonBehaviour dependencyRoot in dependencyRoots)
551556
{
557+
dependencies.Add(dependencyRoot.gameObject);
558+
552559
var behaviourDependencies = ((List<UnityEngine.Object>)serializedObjectReferencesField.GetValue(dependencyRoot))?.Where(e => e != null);
553560

554561
if (behaviourDependencies != null)
@@ -565,9 +572,20 @@ static void RepairPrefabProgramAssets(List<UdonBehaviour> dependencyRoots)
565572

566573
GameObject prefabRoot = null;
567574

568-
if (dependencyObject is GameObject dependencyGameObject && PrefabUtility.IsPartOfPrefabAsset(dependencyGameObject))
575+
if (PrefabUtility.IsPartOfPrefabAsset(dependencyObject))
576+
{
577+
prefabRoot = (GameObject) dependencyObject;
578+
}
579+
else if (dependencyObject is GameObject dependencyGameObject)
569580
{
570-
prefabRoot = dependencyGameObject;
581+
if (PrefabUtility.IsAnyPrefabInstanceRoot(dependencyGameObject))
582+
{
583+
prefabRoot = PrefabUtility.GetCorrespondingObjectFromSource(dependencyGameObject);
584+
}
585+
else if (PrefabUtility.IsPartOfPrefabInstance(dependencyObject))
586+
{
587+
prefabRoot = PrefabUtility.GetCorrespondingObjectFromSource(PrefabUtility.GetNearestPrefabInstanceRoot(dependencyObject));
588+
}
571589
}
572590

573591
if (prefabRoot)

0 commit comments

Comments
 (0)