diff --git a/JotunnModStub/Fenrir/FenrirRace.cs b/JotunnModStub/Fenrir/FenrirRace.cs index 4e55a80..5c00200 100644 --- a/JotunnModStub/Fenrir/FenrirRace.cs +++ b/JotunnModStub/Fenrir/FenrirRace.cs @@ -383,6 +383,8 @@ namespace RacesOfValheim { Component animEvent = currentTransformation.GetComponent("AnimEvent"); if (animEvent != null) Destroy(animEvent); + FormFootsteps.Detach(currentTransformation, prefabName); + // The creature's own animations carry their sounds as events; this is what hears // them. On the object that owns the Animator, because that is where Unity delivers // an animation event - for the wolf that is WolfSmooth, two levels down, not the diff --git a/JotunnModStub/Fenrir/FormFootsteps.cs b/JotunnModStub/Fenrir/FormFootsteps.cs new file mode 100644 index 0000000..d106301 --- /dev/null +++ b/JotunnModStub/Fenrir/FormFootsteps.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace RacesOfValheim +{ + /// + /// Stops a Fenrir form's own animations from stepping on the player's FootStep. + /// + /// The form's CharacterAnimEvent resolves its FootStep in Awake, from + /// GetComponentInParent<Character>() - and a form parented under the player finds the + /// PLAYER. So when the Ulv's 'Run' clip fires FootStep('LeftHand') and FootStep('RightHand') + /// for its front paws, vanilla looks for feet with those names on a human rig, finds none, and + /// logs "FAiled to find foot:LeftHand" twice per stride. That is the warning a user reported. + /// + /// Nothing is lost by cutting the link. The player's hidden Visual keeps animating (the hider + /// only switches renderers off), and FootStep drives its steps from that animator's footstep + /// curve, so the form already has footsteps. A form event naming a foot the player does have + /// would only play a second step on top of that one. + /// + /// CharacterAnimEvent.FootStep checks m_footStep before calling it, so nulling the field is + /// all it takes. It has to happen after Instantiate, which is when that Awake has run. + /// + internal static class FormFootsteps + { + private static readonly HashSet logged = new HashSet(); + + public static void Detach(GameObject form, string formName) + { + if (form == null) return; + + int detached = 0; + foreach (CharacterAnimEvent cae in form.GetComponentsInChildren(true)) + { + var field = HarmonyLib.Traverse.Create(cae).Field("m_footStep"); + if (field.GetValue() == null) continue; + field.SetValue(null); + detached++; + } + + if (logged.Add(formName)) + { + Jotunn.Logger.LogInfo( + $"[FenrirForm] '{formName}': {detached} animation-event receiver(s) cut from the player's FootStep."); + } + } + } +} diff --git a/JotunnModStub/ZdoVisualSync.cs b/JotunnModStub/ZdoVisualSync.cs index 686a831..93422ed 100644 --- a/JotunnModStub/ZdoVisualSync.cs +++ b/JotunnModStub/ZdoVisualSync.cs @@ -212,7 +212,9 @@ namespace RacesOfValheim m_currentFormInstance.transform.localRotation = Quaternion.identity; Component animEvent = m_currentFormInstance.GetComponent("AnimEvent"); if (animEvent != null) Destroy(animEvent); - + + FormFootsteps.Detach(m_currentFormInstance, currentForm); + // Clean up colliders on remote visuals foreach (var col in m_currentFormInstance.GetComponentsInChildren()) {