Fix NullReferenceException for pawns with no needs (OWD compat)#5
Open
junikka wants to merge 1 commit intoaRandomKiwi:mainfrom
Open
Fix NullReferenceException for pawns with no needs (OWD compat)#5junikka wants to merge 1 commit intoaRandomKiwi:mainfrom
junikka wants to merge 1 commit intoaRandomKiwi:mainfrom
Conversation
Pawns from mods like "One With Death" can have null needs tracker or null timetable, causing crashes in guard logic. Added null checks for pawn.needs and pawn.timetable across all affected code paths. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pawn.needsin all guard need-check functions inUtils.csandThinkNode_ConditionalNeedPercentageBelow.cscp.needs.mood.thoughts.memoriesinComp_Guard.ReassureSurroundingPawns()pawn.timetableinThinkNode_ConditionalShouldGuardSpot,ThinkNode_ConditionalShouldPatrol, andThinkNode_ConditionalShouldSearchAndKillProblem
Mods like "One With Death" create pawns (zombies) that have no needs tracker (
pawn.needs == null) and possibly no timetable. When these pawns interact with Guards For Me code paths, the game throwsNullReferenceExceptionbecause the code assumes all pawns have needs.The existing code in
Utils.cscorrectly null-checks individual needs (e.g.,pawn.needs.rest != null) but does not check whetherpawn.needsitself is null. The crash happens before reaching those checks.Changes (1.6 only, 6 files)
Utils.csif (pawn.needs == null) return false;to all 7 need-check functionsThinkNode_ConditionalNeedPercentageBelow.cspawn.needsnull check + null check onTryGetNeed()return valueComp_Guard.csTryGainMemorywithcp.needs?.mood?.thoughts?.memories != nullThinkNode_ConditionalShouldGuardSpot.cspawn.timetable != nullbefore accessingCurrentAssignmentThinkNode_ConditionalShouldPatrol.csThinkNode_ConditionalShouldSearchAndKill.csTest plan
🤖 Generated with Claude Code