Skip to main content

Part 3: Mapping Stats

Stats can automatically be mapped to any existing character controller quickly and easily using the Stat Mapper component. You don't even need to have your Stat Source on the same GameObject! Select the GameObject with your character controller, click the "Add Component" button and add "Stat Mapper".

"Mapping Stats"

Stat Source#

If you have a Stat Source (such as Player Character Stats) already on your controller, this will automatically populate.

"Stat Source"

If you'd like to get your source from another object simply select "Find In Registry" and enter the associated key.

Mappings#

"Mappings"

By pressing the "Add Mapping" button you can add a new entry. Drag your controller componet into the Target box. The Field dropdown will automatically populate with every int, single, double, float, long, and bool field available on that controller. Select the one you want to map to and then provid the id of the Stat you wish to map.

If you want the controller to be able to assign values back to that Stat click the Bi-Directional option.

"Mappings"

In the example above we're mapping a Stat with the id of "sta" to a field on our Character Controller call "stamina". This controller already has code to drain stamina when sprinting. Since we selected Bi-Directional when the value of "stamina" on the Character Controller changes it will also change the value of the Stat "sta".