RacesOfValheim/JotunnModStub/Fenrir/FormFootsteps.cs
kanym 5bdd7200a5 fix(fenrir): the Ulv no longer asks the player for feet called LeftHand
The form's CharacterAnimEvent finds its FootStep on the nearest Character
up the hierarchy, which for a form parented under the player is the player.
The Ulv's Run clip names its front paws LeftHand and RightHand, a human rig
has neither, and vanilla logged "FAiled to find foot" twice per stride.

The form's receivers are now cut from the player's FootStep, on the local
form and on the copy other players see. The footsteps stay: the hidden
human animator keeps running and FootStep steps off its curve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 18:17:37 +02:00

47 lines
2 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// 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&lt;Character&gt;() - 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.
/// </summary>
internal static class FormFootsteps
{
private static readonly HashSet<string> logged = new HashSet<string>();
public static void Detach(GameObject form, string formName)
{
if (form == null) return;
int detached = 0;
foreach (CharacterAnimEvent cae in form.GetComponentsInChildren<CharacterAnimEvent>(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.");
}
}
}
}