Modding: How to Create a New Unit

## # Creating a new unit: Example with Conscripts

In this step by step process we will detail how to create a glorious **Conscripts** unit for the Imperial Guard.
Tis is the one used in one of current mods. (link to be added later)

For that to work, you'll just need a text editor, such as **Notepad++** or **Sublime Text**, and basic understanding of **XML structure**.

## # Step One: Take a stable base

First you should locate a stable example. In this process we will use the Guardsman (Data\World\Units\AstraMilitarum\Guardsman.xml) as our example. Head to that folder.

## # Step Two: Create the Unit and make it recruitable

Copy that file into a new one that you will name "Conscripts.xml".

To make that unit recruitable, locate Data\World\Buildings\AstraMilitarum\Infantry.xml and add one line under Guardsman, to look like this:

```
	<produceUnit unit="AstraMilitarum/Guardsman"/>
	<produceUnit unit="AstraMilitarum/Conscripts"/>

```

## # Step Three: Address Core dependencies

At this point the game will crash on startup.
You need to address text dependencies.
Head to Data\Core\Languages\English folder and edit the Units.xml file there.

Add this content before the end of file:

```
        <entry name="AstraMilitarum/Conscripts" value="Conscripts"/>
	<entry name="AstraMilitarum/ConscriptsDescription" value="Light infantry unit."/>
	<entry name="AstraMilitarum/ConscriptsFlavor" value="This is my description of the glorious Conscripts unit."/>

```

## # Step Four: Address Graphic dependencies

Now the hardest part.
You need to address all video dependencies: this part includes the mesh, the animations, weapon animations and sprites.

Since the XML file currently uses the guardsman mesh and animations, normally you should only have to **create the sprites** so we'll cover that first.
To do that search for "Guardsman" in Video\Textures and duplicate these files and rename these copies as Conscripts.

The two files you are looking for are both called "Guadsman.dds" and they are located in

1. Data\Video\Textures\Icons\Overlay\Units\AstraMilitarum
2. Data\Video\Textures\Icons\Units\AstraMilitarum

For instance in Data\Video\Textures\Icons\Units\AstraMilitarum you should copy Guardsman.dds into Conscripts.dds

Do the same for all occurrences.

## # Step Five: Address More Graphic dependencies

Alternatively, you could also duplicate the mesh and animations, by searching for "Guardsman" in the whole "Data\Video" directory and following the same process.

That step should not be mandatory as only Data\Textures should be mandatory.

## # Step Six: Address Sound dependencies

There is no current audio dependency because we are using Guardsman sounds.
If you would like to add your own sounds, you should check Data\Audio.

First you could add your own sounds in Data\Audio\cached by searching for "Guardsman" and duplicating them.
Secondly you have to look at Data\Audio\Mixer.xml and duplicate a few lines to make sure your new sounds are being used and do not crash the game.

## # Step Seven: Testing and debugging!

At this point dependencies are all addressed. Yet there may still be crashes!

Make sure you did not forget anything.

If you tried to use your own mesh by editing the unit file created on step 2, redirect instead to the guardsman mesh.

In our tests using a custom mesh failed because of data inside the mesh you duplicated, which mentioned the Guardsman itself in its binary code.

It's safe however to use your own materials, but you have to use Guardsman mesh and animations.

## # Step Eight: Let's make it better!

Now that we have a working Conscript we can make it better. As of now it's just a Guardsman.

You should use the guide for editing units, and adjust some values.

* You should increase its size to 20 men in ranks of 5, 6 or 7.
* You could increase the cost in Food; after all they are 20 men; and the consumption of food too, this should not be an endgame power unit but a way to soak up an attack.
* You should also reduce the attributes of each soldier because they would be too strong. In our example we put Morale to 3, ranged accuracy and melee accuracy to 4, and armor to 3.
* Also, for balance reasons, we also removed the Krak Grenade ability.

## # The Final Conscripts

The final Conscripts.xml file content is here for you to enjoy.

```
<?xml version="1.0" encoding="utf-8"?>
<unit>
	<model>
		<unit mesh="Units/AstraMilitarum/Guardsman"
				material="Units/AstraMilitarum/Conscripts"
				idleAnimation="Units/AstraMilitarum/ConscriptsIdle"
				idleAnimationCount="3"
				idleContinuously="1"
				normalWeight="0.1"
				scale="0.75 0.75 0.75"
				bloodBone="ChestBone"
				walker="1"/>
	</model>
	<group size="20" rowSize="7" memberDeltaX="50" memberDeltaY="30"/>
	<weapons>
		<weapon name="Lasgun">
			<model>
				<beamWeapon mesh="Weapons/AstraMilitarum/GuardsmanLasgun"
						material="Weapons/AstraMilitarum/GuardsmanLasgun"
						bone="RightHandBone"
						muzzleBone="GuardsmanLasgunMuzzle0"
						fireInterval="0.5"/>
			</model>
		</weapon>
		<weapon name="FragGrenade" slotName="FragGrenade" enabled="0">
			<model>
				<grenadeWeapon muzzleBone="LeftHandBone"/>
			</model>
		</weapon>
	</weapons>
	<modifiers>
		<modifier visible="0">
			<effects>
				<armor set="3"/> <!-- %armor set armor=5+ -->
				<meleeArmorPenetration set="0.0"/> <!-- %meleeArmorPenetration set strength=3 -->
				<food set="-2.0"/> <!-- %food set tier=4 factor=1 -->
				<foodCost set="20.0"/> <!-- %foodCost set tier=4 factor=0.5 -->
				<hitpointsMax set="2.0"/> <!-- %hitpointsMax set toughness=3 wounds=1 -->
				<meleeAccuracy set="4"/> <!-- %meleeAccuracy set weaponSkill=3 -->
				<meleeAttacks set="1"/>
				<!-- <meleeInitiative set="3"/> -->
				<oreCost set="10.0"/> <!-- %oreCost set tier=4 factor=0.5 -->
				<meleeDamage set="1"/> <!-- %meleeDamage set strength=3 -->
				<moraleMax set="3"/>
				<movementMax set="2"/>
				<productionCost set="24.0"/> <!-- %productionCost set tier=4 factor=1 -->
				<rangedAccuracy set="4"/> <!-- %rangedAccuracy set ballisticSkill=3 -->
			</effects>
		</modifier>
	</modifiers>
	<strategyModifiers>
		<modifier>
			<effects>
				<increaseInfantryScore set="1.0"/>
			</effects>
		</modifier>
	</strategyModifiers>
	<actions>
		<attack>
			<model>
				<action animation="Units/AstraMilitarum/ConscriptsAttack"
						beginFire="0.35" endFire="2.5"/>
			</model>
		</attack>
		<die>
			<model>
				<action animation="Units/AstraMilitarum/ConscriptsDie"
						animationCount="3"
						sound="Units/MediumUnarmoredDie"
						soundCount="4"/>
			</model>
		</die>
		<idle>
			<model>
				<action/>
			</model>
		</idle>
		<move>
			<model>
				<action animation="Units/AstraMilitarum/ConscriptsMove"
						sound="Units/AstraMilitarum/InfantryMove"
						soundCount="4"/>
			</model>
		</move>
		<throwGrenade weaponSlotName="FragGrenade" cooldown="10"
				requiredUpgrade="AstraMilitarumExpanded/FragGrenade">
			<model>
				<action animation="Units/AstraMilitarum/ConscriptsGrenade"
						beginFire="0.833333333333"/>
			</model>
		</throwGrenade>
		<mediPack cooldown="10" requiredUpgrade="AstraMilitarum/MediPack">
			<model>
				<action bone="ChestBone"
						sound="Actions/Heal"/>
			</model>
			<targets>
				<selfTarget>
					<conditions>
						<unit>
							<damaged/>
						</unit>
					</conditions>
					<areas>
						<area affects="Unit">
							<modifiers>
								<modifier>
									<effects>
										<hitpointsFraction add="0.5"/>
									</effects>
								</modifier>
							</modifiers>
						</area>
					</areas>
				</selfTarget>
			</targets>
		</mediPack>

	</actions>
	<traits>
		<trait name="ExtraInfantryArmour" requiredUpgrade="AstraMilitarum/ExtraInfantryArmour"/>
		<trait name="VoxCaster" requiredUpgrade="AstraMilitarum/VoxCaster"/>
	</traits>
</unit>

```

Back to Unit modding menu
Back to Modding page