Hi,
I'm trying to add a new filter category for various foods, which needs to include meat. In xml this is fairly simple, I just create the thing category def and the add it to the foods with this:
<thingCategories><li>New Category</li></thingCategories>
Doing the above adds the food to the correct filter. I can also use C# to confirm the new category is added to ThingDef.thingCategories with this:
foreach (ThingCategoryDef thingCategory in DefDatabase<ThingDef>.GetNamed("Name").thingCategories)
{
Log.Message(thingCategory.defName.ToString());
}
So naturally, I assumed I can just use C# to add the new thingCategory to the implied meat def.
DefDatabase<ThingDef>.GetNamed("Meat_Thrumbo").thingCategories.Add(ThingCategoryDef.Named("Category"));
The above results in a log message showing Thrumbo meat is in both the meat and new categories. However, in filters it stays only in meat.
I also tried replacing the whole thing:
List<ThingCategoryDef> list = new List<ThingCategoryDef>();
list.Add(ThingCategoryDef.Named("Category"));
DefDatabase<ThingDef>.GetNamed("Meat_Thrumbo").thingCategories = list;
Now the Log Message shows thrumbo meat is only in the new category, but in filters it remains a meat and only a meat. The above methods work to add comps to meat. The above do not work to change the filters of non-meats. Thus, there must be something special about the filters. If anyone can shed some light on why I would appreciate the help.
In case anyone is curious, you have to add it to the TreeNode_ThingCategory.
Sorry to resurrect such an old thread, but could you give an example of what you mean by adding to the TreeNode_ThingCategory?