Hey guys, so below is the code to get the time based on the distance. This works in both dev and shipping builds and functions perfectly in single player. However, I still have one minor issue with multiplayer - this function returns zero for client simulated proxies. So if you’re a client who’s also hosting the server (listen server), you can start and stop just fine, your buddies can start and stop just fine on their local machines, you can even see your buddies start and stop just fine, but your buddies don’t see your or anyone else’s starting/stopping animations . Could I get some help figuring out why this is happening?
float UMyAnimInstance::CalculateDistanceCurveTime(UAnimSequenceBase* Sequence, float Distance)
{
// We have to use smart names and set our animations' compression settings to "Uniform Indexable"
// in order to get curve data for development and shipping builds.
FSmartName CurveSmartName;
const bool bCurveExists = Sequence->GetSkeleton()->GetSmartNameByName(USkeleton::AnimCurveMappingName, DistanceCurveName, CurveSmartName);
if (bCurveExists)
{
// Get an array of keys from the DistanceCurve.
const FAnimCurveBase* CurveData = Sequence->GetCurveData().GetCurveData(CurveSmartName.UID);
const FFloatCurve* DistanceCurve = static_cast<const FFloatCurve*>(CurveData);
TArray<FRichCurveKey> DistanceCurveKeys = DistanceCurve->FloatCurve.Keys;
for (int32 i = 0; i < DistanceCurveKeys.Num(); i++)
{
// Look for the first key that has a value greater than or equal to the Distance.
if (DistanceCurveKeys[i].Value >= Distance)
{
// The first key found is the primary key, and the secondary key
// is initially set to zero to prevent any divide by zero errors.
const float PrimaryKeyValue = DistanceCurveKeys[i].Value;
const float PrimaryKeyTime = DistanceCurveKeys[i].Time;
float SecondaryKeyValue = 0;
float SecondaryKeyTime = 0;
if (i > 0)
{
// This is not the first iteration of the loop, so secondary key will be
// the key before the primary key.
SecondaryKeyValue = DistanceCurveKeys[i - 1].Value;
SecondaryKeyTime = DistanceCurveKeys[i - 1].Time;
}
// Calculate a delta value and a delta time between the two keys.
const float DeltaValue = SecondaryKeyValue - PrimaryKeyValue;
const float DeltaTime = SecondaryKeyTime - PrimaryKeyTime;
return ((DeltaTime / DeltaValue) * (Distance - PrimaryKeyValue)) + PrimaryKeyTime;
}
}
}
return 0.f;
}