How do I fix this error with PawnKindDefOf?

Started by Uruails, April 10, 2021, 12:52:02 PM

Previous topic - Next topic

Uruails

I'm currently getting an error while trying to mod, it's saying in a hint that I can use ResolveReferences() in the C# code for PawnKindDefOf, how do I implement that. I'm trying to make a custom spawner class for spawning colonists for a mod a friend of mine wants to be made. Here is the code I'm certain is the issue

private static PawnKindDef colonist = PawnKindDefOf.Colonist;                        This part right here.
                                                                                                                    V      
public List<PawnKindDef> spawnablePawnKinds = new List<PawnKindDef>{colonist};

Rimworld Error:
Tried to use an uninitialized DefOf of type PawnKindDefOf. DefOfs are initialized right after all defs all loaded. Uninitialized DefOfs will return only nulls. (hint: don't use DefOfs as default field values in Defs, try to resolve them in ResolveReferences() instead) Debug info: DirectXmlToObject is currently instantiating an object of type Rimpaperwork.CompProperties_SpawnColonist
Verse.Log:Warning(String, Boolean)

RawCode

you can't use private fields from game's classes in your code. (directly)

it does not matter when you do it, runtime will throw exception ever if you managed to compile such code.