Sunday, October 12, 2014

AnimNotify does not always fire

AnimNotify can be VERY unreliable. It is possible (but with very low probability) that the notify is NOT fired even if the blend weight passes its MinTriggerWeight. From experiments, I found animnotify sometimes does not fire in both clients and server.

I don't know what causes this, however, I suspect that it is because of a lag that somehow cause the engine to skip the notify.

I first hypothesize that if I can set MinTriggerWeight to zero, the animnotify should always fire given the sequence is play. In Editor, MinTriggerWeight cannot be set to zero (it has to be a small positive value). I suspected that why I can't set this to zero. In C++, the MinTriggerWeight corresponds to the float variable TriggerWeightThreshold. That variable will be used in UAnimInstance::AddAnimNotifies to filter animnotifies. So I created a new class inheriting from AnimInstance class, then make sure that the smallest MinTriggerWeight will always trigger.

But I failed, animnotify does not always fire (at least on client, yet it seems to always fire on server). I suspected that was because of something else... at least I saw a warning saying something like servertrackposition doesn't agree with client's co-occur when the client animnotify doesn't fire ... I suspected that it could lead to notify skipping... Searching in the source code, the client animation montage Position is set to match ServerMontageTrackPosition. This small hack smells fishy... I need to investigate further. In FAnimMontageInstance::Advance, I found that the playing montage will harvest notifies inbetween PrevPosition and Position. However, the PrevPosition is set to "Position" (the same variable that was assigned when server-client track position mismatch) before the Position is advanced to the next... Animnotify from montage with root motion may not be fired because of this!

To fix this, we have to generate animnotifies when that Server-client track position mismatches occur. It is ok, if animnotifies doesn't have great impact gameplay. Yet, sometimes this can be extremely annoying, not to be able to rely on them.

No comments:

Post a Comment