Calling SetKeyTime in iterating KeyHandlesToIndices array can modify the array order, so it breaks the iterator.
Perhaps ShiftCurve also has the same problem.
Here is a work around:
void FIndexedCurve::ScaleCurve(float ScaleOrigin, float ScaleFactor, const TSet<FKeyHandle>& KeyHandles) { if (KeyHandles.Num() != 0) { #if 0 for (auto It = KeyHandlesToIndices.CreateConstIterator(); It; ++It) { const FKeyHandle& KeyHandle = *It; if (KeyHandles.Contains(KeyHandle)) { SetKeyTime(KeyHandle, (GetKeyTime(KeyHandle) - ScaleOrigin) * ScaleFactor + ScaleOrigin); } } } #else //workaround for (auto It = KeyHandles.CreateConstIterator(); It; ++It) { const FKeyHandle& KeyHandle = *It; if (KeyHandlesToIndices.Find(KeyHandle)!=nullptr) { SetKeyTime(KeyHandle, (GetKeyTime(KeyHandle) - ScaleOrigin) * ScaleFactor + ScaleOrigin); } } } #endif }
// Some comments here FRichCurve richCurve; richCurve.AddKey(1.41250002f, 0.f); richCurve.AddKey(1.65260422f, 1.f); // richCurve.ScaleCurve(0.f, 1.19417477f); // int32 i = 0; for (auto&& key : richCurve.GetCopyOfKeys()) { UE_LOG(LogTemp, Log, TEXT("[key%d]time=%f,value=%f"), i++, key.Time, key.Value); }
LogTemp: [key0]time=1.652604,value=1.000000 LogTemp: [key1]time=2.014300,value=0.000000
Values are swapped.
LogTemp: [key0]time=1.652604,value=0.000000 LogTemp: [key1]time=2.014300,value=1.000000
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-247857 in the post.
0 |
Component | UE - Anim - Runtime |
---|---|
Affects Versions | 5.4 |
Target Fix | 5.6 |
Created | Feb 13, 2025 |
---|---|
Updated | Mar 3, 2025 |