A Hat in Time

A Hat in Time

52 ratings
How to Import and Export Armatures Properly for Blender
By Classytimes
This guide will detail how to use Blender to effectively import armatures from A Hat in Time as well as how to effectively export armatures into your mods!
   
Award
Favorite
Favorited
Unfavorite
Introduction
This is a basic guide and only covers importing and exporting relating to armatures. Anything not covered here is most likely not under that specific scope.
Foreword: What If I Am Using a Different Model?
If you are using a model other than Hat Kid's, then chances are that the root bone will have a special name other than "Root." To know what to use in place of "Root" for every instance in the sections below, use the name of the entire armature. The name of the armature will be the second item in your Blender hierarchy (e.g. BaseNode>"Armature">"Model").
Importing: There's a Missing Root Bone!
Blender has a nasty habit of eating the root bone of any model from the game when you import it. This means that if you want to either edit the model and put it back in the game or use your own model with the skeleton (take, for example, custom costumes or playable characters) then you will need to add the root bone back into your model! Here's how you do it.

Begin by importing the model into blender (File>Import>FBX). For this guide, I will be using the model most people will probably be using, Hat Kid.





What we are doing right now is pin-pointing exactly where you need to re-add the root bone. Go into the upper right corner and open the BaseNode heirarchy to reveal the armature, named "Root."



Go back to your main view of the model. We want to move the 3D Cursor to the exact location of the armature. To do this, hold Shift+S and select "Cursor to Selected."



This next part is optional, but I think it makes the next few steps easier. I'm hiding the main body mesh by selecting it and pressing H. Now then, re-select the armature "Root" and go into Edit Mode.



Now, add a new bone.



Wow, that bone is way too big! We might want to shrink it down before we move on to the next step. With the new bone selected, change the Transform Pivot Point to "3D Cursor" and scale down your new bone. The shortcut for scaling is S.



Now that our bone is a decent size, we want to position it correctly to line up with the rest of the janky armature. For this purpose, I recommend copying the locations and roll of the head and tail of a spine bone. To keep it down in the root position though, let your new bone's X location value stay the same (make sure the head and tail X values are 0 after setting the Y and Z values) and only copy the spine bone's Y and Z location values. Also, I am not positive how much this will affect matters, but I always copy the roll of the bone as well, which is -6.8 in this case. To bring out this handy menu popup in the screenshot that tells you this location info, hit N.



Okay, our bone is beautifully in place now. It still is named "Bone" though, and that's no good. Go back into the upper right and rename it to "Root" and remember that capitalization is important!



Next, for the sake of keeping things tidy, you still have two things named "Root" above your bone, and that may get confusing. It may be best to rename those as well, so sometimes I just go with a generic "SkeletalMesh" or "Skelmesh." As long as they have separate names that you are fine with, then you're good.

Now, every other bone that is sitting at the same level as your Root bone will have to become children of your Root bone. To do this, select the bone in edit mode (preferably through selecting them in the upper right) and set the bone's parent to "Root" from the "Bone Properties." Do this for all of the bones that are on the same level as your Root.



The armature has been successfully repaired! What about the model though? It is missing weight data for the Root bone! Thanks a lot Blender. No worries, we can restore the weight of the Root pretty simply.
Importing: There's Missing Weight Data!
In order to restore weight data to our model, go to the bottom right with your model selected and go to the "Object Data Properties" tab. Once there, you should be greeted by the Vertex Groups in full view. Go to the right and click on the plus icon (+) to add a new vertex group. Name it "Root" to match with your new bone, and remember again that capitalization is important!



In Edit Mode, select every single vertex on the model. The shortcut for that is A. Go back to the vertex groups, and click the "Assign" button while you have the "Root" vertex group selected. For those of you who aren't completely new to Blender, you may think I am committing a grave crime. Bear with me for a second, I promise this is for a reason.



Now, click on the lock icon next to the "Root" vertex group. After you do this, go to the dropdown menu in the screenshot below and invert the locks. This will lock every single vertex group except for the Root.



Go into Weight Paint Mode and use the "Normalize All" function (Weights>Normalize All).



If nothing happens, look in the bottom left and make sure that the "Lock Active" box is NOT ticked.



For Hat Kid's model specifically, part of her leg model is weighted to the Root as well. Repeat all of these steps for any other models that need weight restoration. Congratulations, you have successfully restored the Root bone's weights to the model!
Exporting: My Model is Not Animating Correctly In-Game!
Note: the contents of this section are based on this guide[krisredbeard.wordpress.com]. I am detailing this part for the sake of convenience instead of simply putting a link.

For some odd reason, Blender likes to add a new root bone when you export to FBX. The Modding Tools don't like that sort of thing, so your models will not animate correctly unless you prevent Blender from doing this. Locate Blender's FBX export python script by navigating to C:\Program Files\Blender Foundation\Blender\"Version"\scripts\addons\io_scene_fbx\export_fbx_bin.py

This is a protected file, so you need administrator permissions to edit it. Open any text editor of your choosing (like Notepad) in Administrator mode. Once you have the specified file open in your text editor in Admin mode, find the following lines:
elif ob_obj.type == 'EMPTY' or ob_obj.type == 'ARMATURE': empty_key = data_empties[ob_obj] connections.append((b"OO", get_fbx_uuid_from_key(empty_key), ob_obj.fbx_uuid, None))
It is quite a lengthy document, so it helps to simply have the computer to the searching for you. Hit Ctrl+F and search for elif ob_obj.type == 'EMPTY', and it should find the necessary lines immediately. Put a pound symbol (#) before each of those three lines. It should now look like this:
# elif ob_obj.type == 'EMPTY' or ob_obj.type == 'ARMATURE': # empty_key = data_empties[ob_obj] # connections.append((b"OO", get_fbx_uuid_from_key(empty_key), ob_obj.fbx_uuid, None))
Save the file and restart Blender. Blender will no longer add a new root bone by itself. Remember, if you get a new version of Blender or upgrade your current version, you will most likely have to do this again!
Conclusion
Now you're an armature-using master! Get out there and show Blender you mean business!
20 Comments
Yellow Dice Sep 30, 2024 @ 11:30am 
There's 2 more things, when exporting put the geometry thing to face instead of normals. If mesh still looks weird in editor, select all verticles in edit mode press m and click "by distance" this means merging by distance or whatever and don't mess with its value, then export and reimport mesh then it should be fine.
ourhillclan03 Jun 8, 2023 @ 7:14pm 
THANK YOU SO MUCH :steamthumbsup:
CreativeCreeper May 14, 2023 @ 12:29am 
It somewhat fixed my model, but it's still sideways but this time it's facing down, is there a fix to this?
The Geeler Nov 27, 2022 @ 2:52am 
I couldn't find the one used in the tutorials, and I found the one I linked under a different tutorial
Classytimes  [author] Nov 26, 2022 @ 3:49pm 
I'm not sure where you got it, but in the future, you should be getting all of your game models from the modding tools. You can never be too careful downloading files from the internet!
The Geeler Nov 26, 2022 @ 7:10am 
Which model did you use??
Lexi Lunarpaw Apr 6, 2021 @ 3:43pm 
and im pretty sure if i remember correctly i exported it doing the empty level thing but i could be wrong
Lexi Lunarpaw Apr 6, 2021 @ 3:41pm 
@Classytimes Bad news:
i can't and won't use Discord due to the Splatoon RP community driving me out if i ever make an account due to an old "Friend"
Classytimes  [author] Apr 6, 2021 @ 3:39pm 
I'm not positive on what exactly caused this, but my first guess is the way you exported it. Many recommend you drag it into an empty level. However, I recommend opening the head in the Animset viewer, adding the body and leg mesh in the drop-down menus on the left, going to the Animset tab, adding the hatkidv2 animations, and then going to File>export FBX animation. If you need further assistance, don't hesitate to reach out to me on the hat in time discord server!
Lexi Lunarpaw Apr 6, 2021 @ 2:35pm 
https://steamcommunity.com/sharedfiles/filedetails/?id=2448913287&fileuploadsuccess=1
this is what happens whenever i try to import Hat Kid to try to use her armature and i don't know how to fix it
on top of that when ever i try to import an fbx into the editor it says its out of date...