Help with animfile (attaching weapon to unit)

Not sure if this is the right place to ask, but I’m fairly new to modding and could use some help. I’m trying to attach a Fusilier sword to the left hip of SPC_Cooper, but it only works for the walk animation. When he’s idle, it kinda floats in his left hand. Here’s the animfile code I have for reference:

bone_hat Bip01 Prop2 bone_pistol bone_sword Bip01 Prop1 torcheffects\projectiles\torch.xml hammerhammerunits\attachments\hammer_villagerIdlehammer hathatunits\infantry_ranged\regular\regular_hat_age5Idlehat pistolpistolunits\spc\major_cooper\spc_pistolIdlepistol swordswordunits\mercenaries\fusilier\fusilier_swordIdlesword ModelCompunits\spc\major_cooper\spc_major_cooperdefaultshadows_selections\shadow_circle_32x32shadows_selections\selection_hero_64x64shadows_selections\shadow_hero_64x641.501.50 Idleanimation_library\shared\human_idle_generic_AModelComp Boredanimation_library\shared\human_bored_generic_AModelComp Walkanimation_library\shared\human_walk_generic_A0.140.61ModelComp Joganimation_library\shared\jog_generic0.600.10ModelComp Runanimation_library\shared\run_generic0.080.60ModelComp Raze_Idleanimation_library\shared\torch_throw_idleModelComp Raze_Attackanimation_library\shared\torch_throwA0.610.44animation_library\shared\torch_throwB0.560.41ModelComp Buildanimation_library\villager\villager_male_build10.360.661.00animation_library\villager\villager_male_build20.460.761.00ModelComp Pickupanimation_library\explorer\pickup_explorer_A0.31ModelComp CombatIdleanimation_library\explorer\combat_idleModelComp HandAttackanimation_library\2_leg_attack\human_attack_sword_a0.59ModelComp RangedAttackanimation_library\SPC\cooper\ranged_attack0.430.430.43ModelComp Reloadanimation_library\SPC\cooper\reloadModelComp Deathanimation_library\shared\human_death_generic_A0.84ModelComp

There looks like there is a lot of stuff missing. Did you just remove all the tags and stuff?
There is a couple of things here. If you want it always to be in the same spot you would need to put it in the ModelComp section. If you want it showing only when they are idle or running etc… you would put it in the corresponding section.
You would also need to attach it to the correct bone. I believe the Carolean and the royal musketeer have their swords out so if you look at those files you can see what bones that need to be add and attach them. Most units all have the same bones.

Thanks for the response! I’m not sure what happened when I pasted the code lol, I’ll try pasting it again here. I did initially attach the sword to the same bone as the Fusilier in the ModelComp section, but the problem persists.

Edit: I think it has to do with the syntax on the forum. It doesn’t seem to read the stuff between less-than and greater-than signs unless it’s formatted a certain way. My code should be fixed now!

<animfile>
  <definebone>Bip01 Prop2</definebone>
  <definebone>bone_pistol</definebone>
  <definebone>bone_sword</definebone>
  <definebone>Bip01 Prop1</definebone>
  <definebone>bone_hat</definebone>
  <attachment>torch<include>effects\projectiles\torch.xml</include></attachment>
  <attachment>hammer<component>hammer<assetreference type="GrannyModel"><file>units\attachments\hammer_villager</file></assetreference></component><anim>Idle<component>hammer</component></anim></attachment>
  <attachment>hat<component>hat<assetreference type="GrannyModel"><file>units\infantry_ranged\regular\regular_hat_age5</file></assetreference></component><anim>Idle<component>hat</component></anim></attachment>
  <attachment>pistol<component>pistol<assetreference type="GrannyModel"><file>units\spc\major_cooper\spc_pistol</file></assetreference></component><anim>Idle<component>pistol</component></anim></attachment>
  <attachment>sword<component>sword<assetreference type="GrannyModel"><file>units\mercenaries\fusilier\fusilier_sword</file></assetreference></component><anim>Idle<component>sword</component></anim></attachment>
  <component>ModelComp<assetreference type="GrannyModel"><file>units\spc\major_cooper\spc_major_cooper</file></assetreference><attach a="hat" frombone="bone_hat" tobone="HEAD" syncanims="0"></attach><attach a="sword" frombone="bone_sword" tobone="Bip01 Prop2" syncanims="0"></attach><decal><effecttype>default</effecttype><texture isfakeshadow="1">shadows_selections\shadow_circle_32x32</texture><selectedtexture>shadows_selections\selection_hero_64x64</selectedtexture><noncinematictexture>shadows_selections\shadow_hero_64x64</noncinematictexture><width>1.50</width><height>1.50</height></decal></component>
  <anim>Idle<assetreference type="GrannyAnim"><file>animation_library\shared\human_idle_generic_A</file></assetreference><component>ModelComp</component></anim>
  <anim>Bored<assetreference type="GrannyAnim"><file>animation_library\shared\human_bored_generic_A</file></assetreference><component>ModelComp</component></anim>
  <anim>Walk<assetreference type="GrannyAnim"><file>animation_library\shared\human_walk_generic_A</file><tag type="FootstepLeft" footprinttype="HumanLeft">0.14</tag><tag type="FootstepRight" footprinttype="HumanRight">0.61</tag></assetreference><component>ModelComp</component></anim>
  <anim>Jog<assetreference type="GrannyAnim"><file>animation_library\shared\jog_generic</file><tag type="FootstepLeft" footprinttype="HumanLeft">0.60</tag><tag type="FootstepRight" footprinttype="HumanRight">0.10</tag></assetreference><component>ModelComp</component><attach a="knife" frombone="MASTER" tobone="Bip01 Prop1" syncanims="0"></attach></anim>
  <anim>Run<assetreference type="GrannyAnim"><file>animation_library\shared\run_generic</file><tag type="FootstepLeft" footprinttype="HumanLeft">0.08</tag><tag type="FootstepRight" footprinttype="HumanRight">0.60</tag></assetreference><component>ModelComp</component><attach a="knife" frombone="MASTER" tobone="Bip01 Prop1" syncanims="0"></attach></anim>
  <anim>Raze_Idle<assetreference type="GrannyAnim"><file>animation_library\shared\torch_throw_idle</file></assetreference><component>ModelComp</component><attach a="torch" frombone="ATTACHPOINT" tobone="L HAND" syncanims="0"></attach></anim>
  <anim>Raze_Attack<assetreference type="GrannyAnim"><file>animation_library\shared\torch_throwA</file><tag type="Attack">0.61</tag><tag type="SpecificSoundSet" checkvisible="1" set="TorchSwing">0.44</tag></assetreference><assetreference type="GrannyAnim"><file>animation_library\shared\torch_throwB</file><tag type="Attack">0.56</tag><tag type="SpecificSoundSet" checkvisible="1" set="TorchSwing">0.41</tag></assetreference><component>ModelComp</component><attach a="torch" frombone="ATTACHPOINT" tobone="L HAND" syncanims="0"></attach></anim>
  <anim>Build<assetreference type="GrannyAnim"><file>animation_library\villager\villager_male_build1</file><tag type="SpecificSoundSet" checkvisible="1" set="Build">0.36</tag><tag type="SpecificSoundSet" checkvisible="1" set="Build">0.66</tag><tag type="SpecificSoundSet" checkvisible="1" set="Build">1.00</tag></assetreference><assetreference type="GrannyAnim"><file>animation_library\villager\villager_male_build2</file><tag type="SpecificSoundSet" checkvisible="1" set="Build">0.46</tag><tag type="SpecificSoundSet" checkvisible="1" set="Build">0.76</tag><tag type="SpecificSoundSet" checkvisible="1" set="Build">1.00</tag></assetreference><component>ModelComp</component><attach a="hammer" frombone="MASTER" tobone="Bip01 Prop1" syncanims="0"></attach></anim>
  <anim>Pickup<assetreference type="GrannyAnim"><file>animation_library\explorer\pickup_explorer_A</file><tag type="SpecificSoundSet" checkvisible="1" set="GatherFruit">0.31</tag></assetreference><component>ModelComp</component></anim>
  <anim>CombatIdle<assetreference type="GrannyAnim"><file>animation_library\explorer\combat_idle</file></assetreference><component>ModelComp</component><attach a="sword" frombone="bone_sword" tobone="PROP1" syncanims="0"></attach></anim>
  <anim>HandAttack<assetreference type="GrannyAnim"><file>animation_library\explorer\melee_attack</file><tag type="Attack">0.27</tag></assetreference><component>ModelComp</component><attach a="sword" frombone="bone_sword" tobone="PROP1" syncanims="0"></attach></anim>
  <anim>RangedAttack<assetreference type="GrannyAnim"><file>animation_library\SPC\cooper\ranged_attack</file><tag type="Attack">0.43</tag><tag type="SpecificSoundSet" checkvisible="1" set="PistolShot">0.43</tag><tag type="Particles" particlename="pistolshot_right">0.43</tag></assetreference><component>ModelComp</component><attach a="pistol" frombone="MASTER" tobone="BIP01 PROP1" syncanims="1"></attach></anim>
  <anim>Reload<assetreference type="GrannyAnim"><file>animation_library\SPC\cooper\reload</file></assetreference><component>ModelComp</component><attach a="pistol" frombone="MASTER" tobone="BIP01 PROP1" syncanims="1"></attach></anim>
  <anim>Death<assetreference type="GrannyAnim"><file>animation_library\shared\human_death_generic_A</file><tag type="SpecificSoundSet" checkvisible="1" set="RagdollImpact">0.84</tag></assetreference><component>ModelComp</component></anim>
</animfile>


Here is a screenshot of the Idle pose for reference. I appreciate the help!


And here’s a screenshot of the walking animation, which is where I want the sword attachment to be. Everything seems to be working properly except for how it looks when the character is idle.

I will have to look at the other models when I get home tonight.

I appreciate it! If you could explain to me how replacetexture works as well, that would be awesome. I’m trying to use this texture to create a new unit, but I don’t know how to get the animfile to find the new texture files. Thanks either way!

An object is attached to the unit in a determined bone, a point from the skeleton of the 3d model, but it’s position will be determined for the animation. Usually, they not change: a general with a pistol in his right hand will attack with it. However, there are some different anims, including that from Janissaries, Fusiliers and Explorers. The Bip_Prop2 bone, that usually belongs to left hand, in animations for these guys will be the back, the other hand or something like this. Try using anims from them, specially Janissaries and Fusiliers, play with whatever works for you

So looking at how the Carolean is set up, it looks like you would need to take you attach statement for the sword and add it after the modelcomp tag for each of the different animations.

I understand the textures but I’m not the greatest at the modeling side of things. But this is how the files all inter-connect. You would start with the protoy.xml file that is found in DATA. Within the unit info (ex: SPCCooper), you set the animfile. Next is the animfile (spc_major_cooper.xml), this will gather everything like the 3d model, textures, animations, etc. and put it all together. The specific line that you will be looking at mostly is the ModelComp line which is basically saying what is the model made up of. This will point you to the next file, the material file (ex: spc_major_cooper.material). Here it will specify what the textures you want to use. BaseColor is how the unit will look. Normals is the shape of the unit, so like if a sheriff’s badge should be sticking out or apart of the fabric. Masks is the texture of the unit, so if something is shiny and metallic or is looks leathery. I don’t know what each color means but that is usually how it is determined. Details is shows what colors should be the player color. Anything in red will be the player color. The material file usually uses the 3d model or gr2 file of the same name. To get it to work properly you would need to include that model as well. One recommendation would be to use variations. you can use the same model and have different variations of how the unit would work. This is how they have normal Hussars and revolution Hussars like Death Hussars and Magyar Hussars. The one last bit of info you will need to keep in mind is that the tactics file within DATA sets what animations are used when a unit does an action. So if a unit is doing a VolleyRangedAttack it will use the ‘RangedAttack’ animation, when it reloads it will use ‘Reload’, when it is idle it will use ‘Idle’.

I hope that explains it. I mostly just learned a lot of this by looking at files and seeing how units were already done and copying them to get the right results. And if it doesn’t I’m sorry, I don’t really use replacetexture or what ever that exactly is, but this is how I go about changing the way a unit looks or even building a new unit.