diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index 04672194b..38aab250f 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog]. ### Removed ### Fixed +- Animation clip length can be changed `#647` ### Security diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c6394b6a..543705683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog]. ### Removed ### Fixed +- Animation clip length can be changed `#647` ### Security diff --git a/Editor/Processors/ApplyObjectMapping.cs b/Editor/Processors/ApplyObjectMapping.cs index 70bcf4d5f..d62d6e88a 100644 --- a/Editor/Processors/ApplyObjectMapping.cs +++ b/Editor/Processors/ApplyObjectMapping.cs @@ -161,6 +161,15 @@ private Object CustomClone(Object o) var newClip = new AnimationClip(); newClip.name = "rebased " + clip.name; + // copy m_UseHighQualityCurve with SerializedObject since m_UseHighQualityCurve doesn't have public API + using (var serializedClip = new SerializedObject(clip)) + using (var serializedNewClip = new SerializedObject(newClip)) + { + serializedNewClip.FindProperty("m_UseHighQualityCurve") + .boolValue = serializedClip.FindProperty("m_UseHighQualityCurve").boolValue; + serializedNewClip.ApplyModifiedPropertiesWithoutUndo(); + } + foreach (var binding in AnimationUtility.GetCurveBindings(clip)) { var newBinding = _mapping.MapBinding(binding); @@ -179,6 +188,16 @@ private Object CustomClone(Object o) AnimationUtility.GetObjectReferenceCurve(clip, binding)); } + // ReSharper disable once CompareOfFloatsByEqualityOperator + if (newClip.length != clip.length) + { + // if newClip has less properties than original clip (especially for no properties), + // length of newClip can be changed which is bad. + newClip.SetCurve( + "$AvatarOptimizerClipLengthDummy$", typeof(GameObject), "m_IsActive", + AnimationCurve.Constant(clip.length, clip.length, 1f)); + } + newClip.wrapMode = clip.wrapMode; newClip.legacy = clip.legacy; newClip.frameRate = clip.frameRate;