how do I override Pawn spawning/loading?

Started by Goldscuttle, November 06, 2019, 06:28:47 PM

Previous topic - Next topic

Goldscuttle

I have a new Pawn class with "extended" properties (more detailed traits). I've got it walking around in an old save but now I realize it has special qualities that are not shared by the pre-existing pawns. I'm okay with making a new game, but the larger question is how to make this class the "default" colonist pawn type that RimWorld spawns in new games without changing anything in Core?  OR would I have to have some "upgrade/cloning" code higher up, such as MapComponent or WorldObjectComp? The goal is to start a completely new game & have all upgraded pawns from scratch, while still using mods like Prepare Carefully, etc.

LeatherCat

You may want look at PawnGenerator class. And method called something like find-player-start-location (don't remember exactly) with return type Vector3.
You may create harmony prefix patch with return false to not call original method.

K

Before you replace every pawn in the game with a new class, there's alternative methods you should probably look at. The replacement approach carries with it the potential for really bad conflicts with other mods.

Have you considered a ThingComp? Depending on how much code you've changed in the base class it may be possible to move the behavior out to a comp that gets added to pawns instead of replacing them.

You can also create a custom Tracker like those that hold the other aspects of pawn behavior (e.g. the HealthTracker or EquipmentTracker). This is a little more involved and has some overhead but you can guarantee that every pawn has one, which isn't necessarily possible with adding comps. You'd also have much more control over the tracker than the comp.

You'll definitely have to use Harmony of course, but realize that you can make any change to the vanilla code that you can think of with Harmony. You can replicate your entire modified class with Harmony if need be and it would play a lot nicer with other mods than changing the class entirely. More complex changes may require the use of the transpiler though, which can be difficult.

LWM

What cases could possibly involve a pawn not having the comp?


K

The comp would have to be instantiated and associated with the pawn, so a Harmony patch would likely be used to accomplish that. However, for example if a mod doesn't use the primary spawning code then a pawn could end up without the comp. With a custom tracker it's possible to guarantee the existence of a tracker when it's accessed. It's probably possible to do the same thing with a comp but less convenient.