better error handling for missing rootnodes or rendernode animationworkers

This commit is contained in:
c0ffee 2024-04-22 17:31:20 -07:00
parent c800084a32
commit 3f7a7bfdc3
2 changed files with 3 additions and 3 deletions

View File

@ -204,10 +204,10 @@ namespace Rimworld_Animations {
public void CheckAndPlaySounds()
{
PawnRenderNode rootNode = pawn.Drawer.renderer.renderTree.rootNode;
PawnRenderNode rootNode = pawn.Drawer?.renderer?.renderTree?.rootNode;
//check if the rootnode has sounds; if so play it
if (rootNode.AnimationWorker is AnimationWorker_KeyframesExtended animWorker)
if (rootNode?.AnimationWorker is AnimationWorker_KeyframesExtended animWorker)
{
SoundDef sound = animWorker.soundAtTick(rootNode.tree.AnimationTick);
if (sound != null)
@ -220,7 +220,7 @@ namespace Rimworld_Animations {
//do the same for all the child nodes
foreach (PawnRenderNode node in rootNode.children)
{
if (node.AnimationWorker is AnimationWorker_KeyframesExtended childrenAnimWorker)
if (node?.AnimationWorker is AnimationWorker_KeyframesExtended childrenAnimWorker)
{
SoundDef sound = childrenAnimWorker.soundAtTick(node.tree.AnimationTick);
if (sound != null)