Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prefab-safe-set): unncecessary prefab overrides are generated #1236

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog].
### Fixed
- maxSquish cannot be configured for mergePB`#1231`
- Error from Optimize Texture if there is Merge Skinned Mesh with material slot animation `#1235`
- Unncecessary Prefab Overrides are Generated with Prefab Safe Set `#1236`

### Security

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The format is based on [Keep a Changelog].
- Reimplement Preview system with NDMF Preview System `#1131` `#1195` `#1218`
- This will prevent issues relates to Animation Mode bug.
- This allows you to preview Remove Mesh components without selecting Mesh OR while in Animation Mode.
- Improved Prefab Safe Set, which are used in MergePhysBone, MergeSkinnedMesh, FreezeBlendShape and more components `#1212` `#1219` `#1221`
- Improved Prefab Safe Set, which are used in MergePhysBone, MergeSkinnedMesh, FreezeBlendShape and more components `#1212` `#1219` `#1221` `#1236`
- This should improve compatibility with replacing base prefab, which is added in Unity 2022.
- Allow multiple component for Remove Mesh components with API `#1216` `#1218`
- This allows non-destructive tools to add Remove Mesh components even if Remove Mesh component are added before.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public PrefabModificationOnScene(SerializedProperty property, int nestCount,

protected override void InitCurrentLayer(bool force = false)
{
_usingOnSceneLayer.boolValue = true;
if (force) _usingOnSceneLayer.boolValue = true;
CurrentRemoves = _onSceneLayer.FindPropertyRelative(Names.Removes);
CurrentAdditions = _onSceneLayer.FindPropertyRelative(Names.Additions);
_prefabLayersSize.Updated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static void OnValidate<TComponent>(TComponent component, Func<TComponent,
{
// if the prefab is created, we clear onSceneLayer to avoid unnecessary modifications
prefabSafeSet.onSceneLayer = new PrefabLayer<T>();
prefabSafeSet.usingOnSceneLayer = false; // this should avoid creating prefab overrides
}
}

Expand All @@ -48,6 +49,7 @@ public static void OnValidate<TComponent>(TComponent component, Func<TComponent,

if (!shouldUsePrefabOnSceneLayer && prefabSafeSet.usingOnSceneLayer)
{
// migrate onSceneLayer to latest layer
var onSceneLayer = prefabSafeSet.onSceneLayer;

if (maxLayerCount == 0)
Expand Down Expand Up @@ -131,7 +133,7 @@ void DistinctCheckArray(ref T[] source, Func<T, bool> filter)
if (shouldUsePrefabOnSceneLayer)
{
var currentLayer = self.onSceneLayer;
self.usingOnSceneLayer = true;
//self.usingOnSceneLayer = true; // this will create prefab overrides, which is not good.
DistinctCheckArray(ref currentLayer.additions, PrefabSafeSetRuntimeUtil.IsNotNull);
DistinctCheckArray(ref currentLayer.removes,
x => x.IsNotNull() && !currentLayer.additions.Contains(x));
Expand Down Expand Up @@ -169,6 +171,7 @@ private static void ApplyModificationsToLatestLayer(PrefabSafeSet<T> self, int m
else
{
// nestCount is not zero: apply to current layer
if (shouldUsePrefabOnSceneLayer) self.usingOnSceneLayer = true;
var targetLayer = shouldUsePrefabOnSceneLayer ? self.onSceneLayer : self.prefabLayers[maxLayerCount - 1];
var additions = new ListSet<T>(targetLayer.additions);
var removes = new ListSet<T>(targetLayer.removes);
Expand Down
Loading