I have just started learning C#. I'm making a game mod for Rimworld and cannot modify the pawn code. Apparently, any of the chained objects may be null. Is there a better way to bail out of the method than what I've done?
Thank you.
private void cleanseParadoxicalMemories(Pawn pawn, Dictionary<string, string> knownPawnIDs)
{
if (pawn.needs == null || pawn.needs.mood == null || pawn.needs.mood.thoughts == null || pawn.needs.mood.thoughts.memories == null)
{
return;
}
// Remove any crazy-making memories from a now-invalid timeline due to traveling across an Einstein-Rosen bridge
// (basically, selective amnesia about everyone not going with us.)
foreach (var paradox in pawn.needs.mood.thoughts.memories.Memories.ToList())
{
if (paradox.otherPawn != null)
{
pawn.needs.mood.thoughts.memories.RemoveMemory(paradox);
}
}
}