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:
parent
ce87e987c9
commit
2f890f95f7
4 changed files with 154 additions and 54 deletions
|
|
@ -333,8 +333,8 @@ namespace RacesOfValheim
|
|||
anim.cullingMode = AnimatorCullingMode.AlwaysAnimate;
|
||||
}
|
||||
|
||||
HideItemInstances(__instance, "m_hairItemInstances");
|
||||
HideItemInstances(__instance, "m_beardItemInstances");
|
||||
HideItemInstances(__instance, "m_hairItemInstance");
|
||||
HideItemInstances(__instance, "m_beardItemInstance");
|
||||
SetHelmetVisible(__instance, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -357,8 +357,8 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
ShowItemInstances(__instance, "m_hairItemInstances");
|
||||
ShowItemInstances(__instance, "m_beardItemInstances");
|
||||
ShowItemInstances(__instance, "m_hairItemInstance");
|
||||
ShowItemInstances(__instance, "m_beardItemInstance");
|
||||
SetHelmetVisible(__instance, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -373,70 +373,61 @@ namespace RacesOfValheim
|
|||
/// first frame after a race change, all of which reach this postfix and none of which
|
||||
/// reach SkeletonRace.
|
||||
///
|
||||
/// Scaled rather than deactivated, because Valheim re-enables the instance whenever it
|
||||
/// refreshes visuals - the approach the Dvergar's hood already proved out.
|
||||
/// Delegates to SkeletonVisuals.SetEquipmentPieceHidden, which scales the wrapper to
|
||||
/// zero and disables its renderers - scale alone leaves a skinned piece (bound to the
|
||||
/// player's own bones rather than its own transform) still drawing, which is what a
|
||||
/// helmet with a skinned cloth or chain part looked like.
|
||||
/// </summary>
|
||||
private static void SetHelmetVisible(VisEquipment visEq, bool visible)
|
||||
{
|
||||
GameObject helmet = Traverse.Create(visEq).Field<GameObject>("m_helmetItemInstance").Value;
|
||||
if (helmet == null) return;
|
||||
|
||||
Vector3 wanted = visible ? Vector3.one : Vector3.zero;
|
||||
|
||||
// Only ever undo our own hiding: another race may legitimately be scaling this.
|
||||
if (!visible && helmet.transform.localScale != Vector3.zero)
|
||||
{
|
||||
helmet.transform.localScale = wanted;
|
||||
}
|
||||
else if (visible && helmet.transform.localScale == Vector3.zero)
|
||||
{
|
||||
helmet.transform.localScale = wanted;
|
||||
}
|
||||
SkeletonVisuals.SetEquipmentPieceHidden(helmet, !visible);
|
||||
}
|
||||
|
||||
private static void HideItemInstances(VisEquipment visEq, string fieldName)
|
||||
{
|
||||
SetItemInstanceActive(visEq, fieldName, false);
|
||||
}
|
||||
|
||||
private static void ShowItemInstances(VisEquipment visEq, string fieldName)
|
||||
{
|
||||
SetItemInstanceActive(visEq, fieldName, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hair and beard live in VisEquipment as a single GameObject (m_hairItemInstance /
|
||||
/// m_beardItemInstance), the same as the helmet - not a list. A previous version of
|
||||
/// this looked for "m_hairItemInstances" / "m_beardItemInstances" (plural), which do
|
||||
/// not exist on VisEquipment, so the reflection lookup silently found nothing and the
|
||||
/// beard never got the SetActive(false) this was supposed to give it. Handling both
|
||||
/// shapes here matches the defensive pattern the Furling race already uses.
|
||||
/// </summary>
|
||||
private static void SetItemInstanceActive(VisEquipment visEq, string fieldName, bool active)
|
||||
{
|
||||
try
|
||||
{
|
||||
var field = typeof(VisEquipment).GetField(fieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
if (field != null)
|
||||
if (field == null) return;
|
||||
|
||||
object value = field.GetValue(visEq);
|
||||
if (value is GameObject go)
|
||||
{
|
||||
var list = field.GetValue(visEq) as System.Collections.Generic.List<GameObject>;
|
||||
if (list != null)
|
||||
if (go != null) go.SetActive(active);
|
||||
}
|
||||
else if (value is System.Collections.Generic.List<GameObject> list)
|
||||
{
|
||||
foreach (GameObject item in list)
|
||||
{
|
||||
foreach (GameObject go in list)
|
||||
{
|
||||
if (go != null) go.SetActive(false);
|
||||
}
|
||||
if (item != null) item.SetActive(active);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"Failed to hide {fieldName}: {e.Message}");
|
||||
Jotunn.Logger.LogWarning($"Failed to set {fieldName} active={active}: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowItemInstances(VisEquipment visEq, string fieldName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var field = typeof(VisEquipment).GetField(fieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
if (field != null)
|
||||
{
|
||||
var list = field.GetValue(visEq) as System.Collections.Generic.List<GameObject>;
|
||||
if (list != null)
|
||||
{
|
||||
foreach (GameObject go in list)
|
||||
{
|
||||
if (go != null) go.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception e) { }
|
||||
}
|
||||
|
||||
// Bones worth reporting on. Not remapped - the player rig has a real 'Jaw' bone and the
|
||||
// name match lands on it correctly, which is exactly why the plain and poison skeletons
|
||||
// always looked right. An earlier attempt pinned this group to the head instead and
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue