[Solved]C# methods of removing a hediff?

Started by kwang4, July 02, 2020, 10:17:22 PM

Previous topic - Next topic

kwang4

Somewhat basic, but I'm trying to remove a hediff from a dead body and returning an item. Method one is finding hediff name using DefDatabase and removing it, which works.

HediffDef h = DefDatabase<HediffDef>.GetNamed("ATPP_HediffVX2Chip");
innerPawn.health.hediffSet.hediffs.Remove(innerPawn.health.hediffSet.GetFirstHediffOfDef(h));


Second is creating a hediff with HediffMaker which has the correct hediffDef inside and targeting the pawn, but it never worked.

                HediffDef h = DefDatabase<HediffDef>.GetNamed("ATPP_HediffVX2Chip");
                Hediff hed = HediffMaker.MakeHediff(h, innerPawn, null);
                innerPawn.health.hediffSet.hediffs.Remove(hed);


Could someone explain why this doesn't work, and a possible fix to do it this way? Targeting and removing or adding hediffs has been a huge weakness of mine in rw modding for a while.

LWM

Fun fact: you can use the debug tools to make an animal pregnant 4 or 5 times. (this is not actually healthy for the animal involved)

Internally, that's represented by having 5 different hediffs that all have the "pregnant" def.

The second approach isn't working because you're creating a new hediff and then asking "Hey, does this pawn have THIS hediff? (the one I just created over here?)" And the game is saying "Nope!" The pawn has a similar hediff with the same stats, same def, etc, but it's not the same.

RawCode

under normal conditions you should just look how game handle hediffs (and any other things) on it's own and do exactly same.

and in most cases removing some object from array is not valid, mostly because objects have cleanup procedure and just removing from array will cause undefined state, like hediff removed but effects are not recalculated.

kwang4

Ahh I get it now. Thanks for the clarification both of y'all!
The pregnant example was pretty hilarious