I want to make a check of a DefOf during my code, but only if such DefOf exists. How do I check if such mod is present?
defof is not part of database and not present at runtime
you should check for thingdef that will be created after parsing specific defof
also your implementation is just wrong, you do not need to check both mod and def, if mod is not present, it's defs obviously not present and additional check is not required.
But how would I check if a defof is present without throwing red errors that it does not exist?
How do I check if Celestials.CelestialsDefOf.O21_CelestialHediff exists?
If I check directly if the pawn has the hediff it throws the error that it does not exist.
post your "check directly" code
Sorry.
if (pawn.RaceProps.Humanlike && !pawn.health.hediffSet.HasHediff(Celestials.CelestialsDefOf.O21_CelestialHediff))
{
float startGrayingHair = pawn.RaceProps.lifeExpectancy / 2;
}
do you understand that you access static variable from other mod and it may be called ever "godlike script" and this is absolutely unrelated to anything in base game?
open that class and check how variable is initialized and use defname directly, without additional hard references.