Attaching Weapons & Armor - Valheim-Modding/Wiki GitHub Wiki
There are two primary ways to attach weapons and armor in Valheim, the use of an attach empty in unity (described below) and attach_skin which allows attachment for more complex objects and multiple attachment points.
If you are here looking to attach a new simple shield, or weapon to your character you should likely use an attach object. This pattern can be seen throughout the Valheim codebase from a ripped unity project. The game determines where to attach your object based on the item type in the item drop script.
Example Simple Attach
This simple attach requires an empty object called attach with your desired mesh as a child. It is also suggested you ensure that colliders are included here so that your mesh will interact with the world.
For more complex weapons or armor you will need to use a skinned mesh through attach_skin. Which is described in detail below.
Skinned Meshes allow rigging your mesh to the character avatar. This gives you a much finer grain level of control for attaching your items to the character, but requires a bit of work up front.
- Build a basic rig from this video (Thanks Hugo!)
- Ensure proper bone reordering
- Do not delete any attachment spots you intend to use at some point for armor/weapons
- Hide all attachment spots you intend to use
- Save this setup in blender
- You can add empties (the plain objects here) by being in object mode -> Add -> Empty -> Plain Axis
Adding Empties in Blender
- Build the weapon or armor you want to use (you probably already have this if you are here!)
-
With your basic rig, import your weapon or armor that you want to use
-
Organizing your objects like below will make export and usage much easier
-
Note that the bodies are kept in this rig but are hidden from view, this is to allow easy alignment for the model hands or body parts when attaching your object
-
-
Setup a Child Of Constraint between your attachable object and its target location. In the above example "weapon_left" has a constraint with the LeftHand_Attach object. Notice that scale is not inherited for the child constraint in this case. This will allow you to scale your weapon/armor as you normally would see fit.
If your weapon/armor does not snap to the attachment point after setting this modifier click "set inverse" then "clear inverse", your item should now have snapped to the attachment point.
-
Setting up the armature modifier
-
In order to setup an armature constraint which will transfer kinetics to your attached piece you will first need to create a vertext group with all pieces of the model selected. If you have multiple models or models attached to different parts, each attachment area will need its own vertext group. Vertext groups should use the same name (and casing) as their target bone attachment. All bones are listed in the Armature, in the example we are attaching a weapon so we are attaching to the LeftHand. Vertext groups are found on object properties by selecting the parent empty or directly selecting the mesh.
-
With the vertext group in place you simple need to apply an armature modifier and tell it to bind to the vertex groups
-
-
(Optional) Adjust your model placement by unhiding the body and BodyFem to determine fit
There are a number of important things to take note of when exporting.
-
Ensure leaf bones are not added
-
Only export selected objects
When you are ready to export hide the body and bodyFem, and select all objects by right clicking on the scene collection and hitting "select objects".
Select Objects
Once all objects are selected, your hierarchy should look like this.
Now proceed to export. You should get an .fbx attach_skin containing the armature and your rigged items.
Unpack this completely to make changes to it in unity and add it to your item. This can be used in conjunction with standard attach eg:
Notes:
- Using Child of and mirroring the size of the parent object will not prevent you from scaling the weapons themselves- and will put the selected object exactly on the attachment point (but likely won't be the right rotation etc), you can still resize the object & rotate/move it etc as needed.
- If you are adding a particle system in unity to a skinned mesh system, you will need to set the particle system to use the
skinned mesh renderer
undershape