Difference between revisions of "Modding Tutorials/Custom Comp Classes"

From RimWorld Wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{BackToTutorials}}
 
{{BackToTutorials}}
Creating a custom comp class is a convenient way to add new functionality to RimWorld.
+
Creating a custom comp class is a convenient way to add new functionality to RimWorld. Comps aren't a formal concept in the code: they're a design pattern used in different places. They allow for a more modular approach to adding functionality to different objects.
  
 
=The types of Components=
 
=The types of Components=
There are many different types of Comps, each well suited for a specific task. From most specific to most generic:
+
These are the places where the Comps design pattern is used, each with differing behaviour suited for their respective area. From most specific to most generic:
 
==HediffComp==
 
==HediffComp==
 
A relatively simple Comp for adding more complex behaviour to Hediffs.
 
A relatively simple Comp for adding more complex behaviour to Hediffs.
  
 
==ThingComp==
 
==ThingComp==
{{Main Article|Modding Tutorials/ThingComp}}
+
{{Main|Modding Tutorials/ThingComp}}
A very powerful Component that is tied to a specific Thing. These are often used to store data, give special functionality to the Thing they're tied to and are one of the building blocks of RimWorld modding and RimWorld in general. While not as powerful as a [[Modding_Tutorials/Def_classes|fully custom class]], they provide plenty of functionality for a lot of general use cases without compatibility issues.
+
A very powerful Component that is tied to a specific Thing. These are often used to store data, give special functionality to the Thing they're tied to and are one of the building blocks of RimWorld modding and RimWorld in general. While not as powerful as a [[Modding Tutorials/Def classes|fully custom class]], they provide plenty of functionality for a lot of general use cases without compatibility issues.
 +
 
 +
==WorldObjectComp==
 +
Like a ThingComp, but for WorldObjects.
  
 
==MapComponent==
 
==MapComponent==
{{Main Article|Modding Tutorials/GameComponent}}
+
{{Main|Modding Tutorials/GameComponent}}
 
Much like a ThingComp, except these exist at the Map level. They're most useful for keeping tracks of multiple things at once, storing data, and can serve as a coordinator or general managing entity.
 
Much like a ThingComp, except these exist at the Map level. They're most useful for keeping tracks of multiple things at once, storing data, and can serve as a coordinator or general managing entity.
  
 
==WorldComponent==
 
==WorldComponent==
{{Main Article|Modding Tutorials/GameComponent}}
+
{{Main|Modding Tutorials/GameComponent}}
 
Similar to a MapComponent, but lives on the World level.
 
Similar to a MapComponent, but lives on the World level.
  
 
==GameComponent==
 
==GameComponent==
{{Main Article|Modding Tutorials/GameComponent}}
+
{{Main|Modding Tutorials/GameComponent}}
 
Similar to a WorldComponent, but lives at the Game level.
 
Similar to a WorldComponent, but lives at the Game level.
  
Line 26: Line 29:
 
* Upon start of the tutorial
 
* Upon start of the tutorial
 
* When the player starts the Scenario Configuration (rolling for colonists)
 
* When the player starts the Scenario Configuration (rolling for colonists)
* When a save is loaded
+
* When a save is loaded from the main menu
  
 
==StorytellerComp==
 
==StorytellerComp==

Latest revision as of 00:43, 12 September 2021

Modding Tutorials
Creating a custom comp class is a convenient way to add new functionality to RimWorld. Comps aren't a formal concept in the code: they're a design pattern used in different places. They allow for a more modular approach to adding functionality to different objects.

The types of Components[edit]

These are the places where the Comps design pattern is used, each with differing behaviour suited for their respective area. From most specific to most generic:

HediffComp[edit]

A relatively simple Comp for adding more complex behaviour to Hediffs.

ThingComp[edit]

A very powerful Component that is tied to a specific Thing. These are often used to store data, give special functionality to the Thing they're tied to and are one of the building blocks of RimWorld modding and RimWorld in general. While not as powerful as a fully custom class, they provide plenty of functionality for a lot of general use cases without compatibility issues.

WorldObjectComp[edit]

Like a ThingComp, but for WorldObjects.

MapComponent[edit]

Much like a ThingComp, except these exist at the Map level. They're most useful for keeping tracks of multiple things at once, storing data, and can serve as a coordinator or general managing entity.

WorldComponent[edit]

Similar to a MapComponent, but lives on the World level.

GameComponent[edit]

Similar to a WorldComponent, but lives at the Game level.

The distinction between a GameComponent and a WorldComponent might not be too obvious, but a GameComponent gets instantiated when a new Game is started:

  • Upon start of the tutorial
  • When the player starts the Scenario Configuration (rolling for colonists)
  • When a save is loaded from the main menu

StorytellerComp[edit]

These are a specific type of Component that determines the behaviour of the storyteller.

Which one to use[edit]

Use whatever is most appropriate, really. Does it deal with a Pawn's health? HediffComp. Is it functionality at Thing level? ThingComp. Does it have to do with two pawns, or multiple items on a map? Probably a MapComponent, or maybe a WorldComponent.