fix(skeleton): hide beard and skinned helmet pieces correctly

The hair/beard hide called into m_hairItemInstances/m_beardItemInstances
(plural), fields that don't exist on VisEquipment - every other race uses
the real singular m_hairItemInstance/m_beardItemInstance, so the beard was
never actually hidden. Fixed the field names and made the helper handle
both a GameObject and a List<GameObject> defensively.

Helmet hiding only scaled the wrapper to zero, which does nothing for a
skinned-mesh piece bound to the player's own bones - it ignores its
wrapper's transform. Added SkeletonVisuals.SetEquipmentPieceHidden, which
scales to zero and disables every child renderer, and used it everywhere
the helmet is hidden (local player, remote players, main-menu preview).

Also added an F8 debug dump of the hair/beard/helmet instance state
(active, renderer enabled, scale) for diagnosing any future visibility
regressions in-game.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
kanym 2026-08-06 12:12:30 +02:00
commit 2f890f95f7
4 changed files with 154 additions and 54 deletions

View file

@ -48,6 +48,37 @@ namespace RacesOfValheim
public static bool IsSkeletonPlayer(Player player) => GetPlayerRace(player) == RaceId;
/// <summary>
/// Fully hides (or restores) one equipped item instance - a helmet, typically.
///
/// Scale-to-zero alone leaves skinned pieces behind: a SkinnedMeshRenderer bound to the
/// player's own bones (some helmets carry a cloth or chain piece skinned that way) is
/// deformed by those bone matrices, not by its GameObject's transform, so zeroing the
/// wrapper's localScale does nothing to it - exactly the "part of the helmet is still
/// there" artifact reported on the Skeleton. Disabling every Renderer underneath has no
/// such exception; combined with the scale it hides both plain and skinned pieces, and
/// is reasserted the same way (Valheim's own visual refresh re-enables the instance and
/// resets its scale, so both must be redone every time visuals rebuild).
/// </summary>
public static void SetEquipmentPieceHidden(GameObject instance, bool hidden)
{
if (instance == null) return;
Vector3 wantedScale = hidden ? Vector3.zero : Vector3.one;
if (instance.transform.localScale != wantedScale)
{
instance.transform.localScale = wantedScale;
}
foreach (Renderer renderer in instance.GetComponentsInChildren<Renderer>(true))
{
if (renderer.enabled == hidden)
{
renderer.enabled = !hidden;
}
}
}
/// <summary>
/// The tier a given player's body should be built for. The ZDO carries it so remote
/// players render at their own standing; without one - the menu preview - fall back to