From fb354c2387dc760e71058197388906d88e4ceb66 Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 17 Oct 2026 19:13:47 +0200 Subject: [PATCH] fix(fenrir): enter the Ulv's Sleep state by hand when the player sits A vanilla Ulv is born asleep: its controller only knows the way out of Sleep, so setting the bool from Idle did nothing. The state is now cross-faded into when the player sits; standing drops the bool and the controller's own 'Sleep to Idle' plays. The log names the state found. --- JotunnModStub/Fenrir/FenrirFormShared.cs | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/JotunnModStub/Fenrir/FenrirFormShared.cs b/JotunnModStub/Fenrir/FenrirFormShared.cs index 3922be6..5ee2233 100644 --- a/JotunnModStub/Fenrir/FenrirFormShared.cs +++ b/JotunnModStub/Fenrir/FenrirFormShared.cs @@ -48,6 +48,9 @@ namespace RacesOfValheim // drives the creature's own sleep through it, and not every creature has one. private Animator sleepChecked; private bool hasSleeping; + private int sleepState; + private bool wasSitting; + private static readonly string[] SleepStateNames = { "Sleep", "sleep", "Sleeping", "sleeping" }; private static readonly System.Collections.Generic.HashSet sleepLogged = new System.Collections.Generic.HashSet(); /// Copies the movement parameters, and says whether the form counts as grounded. @@ -87,14 +90,41 @@ namespace RacesOfValheim { if (p.type == AnimatorControllerParameterType.Bool && p.name == "sleeping") { hasSleeping = true; break; } } + + // The state's name is not readable at runtime, only testable: the clip is 'Sleep', and + // the state is most likely named after it. + sleepState = 0; + string found = "none"; + if (hasSleeping) + { + foreach (string candidate in SleepStateNames) + { + int hash = Animator.StringToHash(candidate); + if (!form.HasState(0, hash)) continue; + sleepState = hash; + found = candidate; + break; + } + } string controller = form.runtimeAnimatorController != null ? form.runtimeAnimatorController.name : form.name; if (sleepLogged.Add(controller)) { Jotunn.Logger.LogInfo($"[FenrirForm] '{controller}' {(hasSleeping ? "has" : "has no")} sleeping animation; " + - (hasSleeping ? "sitting puts it to sleep." : "sitting keeps it idle.")); + (hasSleeping ? $"sitting puts it to sleep (state '{found}')." : "sitting keeps it idle.")); } } - if (hasSleeping) form.SetBool("sleeping", sitting); + if (hasSleeping) + { + form.SetBool("sleeping", sitting); + + // The bool alone never put the Ulv to sleep. A vanilla Ulv is BORN asleep: its + // controller enters Sleep from the start and only knows the way out (Sleep, then + // 'Sleep to Idle' once the bool drops). Nothing leads from Idle back into Sleep, so + // the state is entered by hand when the player sits; standing up drops the bool and + // the controller's own wake-up plays. + if (sitting && !wasSitting && sleepState != 0) form.CrossFadeInFixedTime(sleepState, 0.4f, 0); + } + wasSitting = sitting; return grounded; }