Export UnrealEngine Animation assets to Godot
Background
Godot is a free, open source, light weight, easy to use Game Engine. But it's very minor...
Both of Unity & Unreal Engine have asset stores, that has a large amount of 3d models, animations, sounds, etc.
These assets can be used in other game engines or authoring tools. (except rare cases)
- Links
Godot has poor asset store, so I want to use assets from other game engines.
Let's go!
Advanced Locomotion System V4
Now, I'm going to export This Unreal Engine asset.
https://www.unrealengine.com/marketplace/en-US/product/advanced-locomotion-system-v1
This asset is free, and contains a lot of high quality animations.
I'll get Animation Sequence
assets from this.
Export .glb from Unreal Engine
GLTF is open starndard, and .glb
is a single binary form of it.
I prefer it rather than .fbx
, because the later is closed and it's not natively supported in Godot.
UE5 can export assets as .glb
.
Export Mesh
Search AnimMan
SkeltalMesh from Content Browser.
Right click > Asset Action > Export.
Don't forget to choose .glb
format.
Export settings are default.
Export Animations
By the default, bulk exporting assets is executable from UE Editor.
- Content Browser > Filter > Animation > Animation Sequence
- Select all assets
- Right click > Asset Actions > Export Bulk
But Export bulk isn't compatible for glb export(now fbx only), so I have to write python to bulk export.
# export AnimSequence as .glb
import unreal
rootPath = '/Game/AdvancedLocomotionV4'
outputDir = '/Users/{user_name}/Downloads/ExportALS/' # This case is macOS
# remove preview mesh to reduce export size
exportOptions = unreal.GLTFExportOptions()
exportOptions.export_preview_mesh = False
selectedActors = set()
assetPaths = unreal.EditorAssetLibrary.list_assets(rootPath)
for assetPath in assetPaths:
anim = unreal.EditorAssetLibrary.load_asset(assetPath)
if unreal.MathLibrary.class_is_child_of(anim.get_class(), unreal.AnimSequence):
# export format is automaticaly determined by extension
exportPath = outputDir+anim.get_name()+'.glb'
unreal.GLTFExporter.export_to_gltf(
anim, exportPath, exportOptions, selectedActors)
... and paste this into UE Editor's python console.
- Window > Output Log
- Click console icon > choose
Python
- Paste and enter.
Make animation library (Blender)
Now .glb
files are exported!
Godot can directly import them, Off course, but it's hard to use as it is.
- Many animation file exsists.
- Names are ugly.
- Contains unnecessary bones & animations.
So next, import them to Blender and edit them at once by python script.
- import
AnimMan.glb
- rename armature to
Armature
- this naming is required for Godot to auto-convert to Skelton3D Node when importing
- import all animation .glb files to blender
- delete all the other skeltons except
Armature
- move to Scripting tab
- paste scripts below and run
rename_actions.py
import bpy
actions = bpy.data.actions
loop_names = ["_run_", "_walk_", "_sprint_", "loop", "flail"]
# reanme actions
for action in actions:
action.name = action.name.replace("ALS_", "").replace("_0_Mannequin_Skeleton", "")
action.name = action.name.split(".")[0]
lowername = action.name.lower()
if any([n in lowername for n in loop_names]):
action.name = action.name.split("-")[0] + "-loop"
If animation's name have -loop
suffix, it's marked as loop animation when be imported to Godot.
set_fake_user.py
import bpy
exclude_names = ["lean", "sweep", "accel", "additive", "secondarymotion", "_stop_"]
for action in bpy.data.actions:
action.use_fake_user = True
lower_name = action.name.lower()
if any([n in lower_name for n in exclude_names]):
action.use_fake_user = False
Blender's resource is deleted by closing app if isn't referenced by any objects.
Set fake user for savivng action(animation) to .blend
file.
Some articles says "push actions to NLA editor", but it's not necessary.(maybe)
AdvancedLocomotionSystemV4(ALS) contains some animations which don't work outside UE, so remove them.
remove_unnecessary_bones.py
import bpy
exclude_names = ["ik_", "VB"]
bpy.ops.object.mode_set(mode="EDIT")
armature = bpy.data.objects.get("Armature") # type: ignore
for bone in armature.data.edit_bones:
if any([n in bone.name for n in exclude_names]):
armature.data.edit_bones.remove(bone)
for action in bpy.data.actions:
for fcurve in action.fcurves:
if any([n in fcurve.data_path for n in exclude_names]):
action.fcurves.remove(fcurve)
bpy.ops.object.mode_set(mode="OBJECT")
ALS's skelton has some ik_
, VB
prefixed bones.
These are useful to authoring animation, but not necessary for game engine.
So remove them.
Now ready to use!
Import to Godot
You can import .glb
exported from Blender
or directly import .blend
if you set Godot's EditorSettings > FileSystem > Import > Blender 3 Path
.
As I tried, .glb
is better than .blend
because the later takes a lot of time when importing.
Animation Retargeting
Godot has a animation retargeting feature.
I modify import setting to use this.
- double click
.glb
you imported - select
Skelton3D
from SceneTree. - Retarget > Bone Map > New Bone Map > Profile > New SkeltonProfileHumanoid
- Rest Fixer > Fix Shilhouette > Enable = true
That's all!
ALS's skelton are like a human shape, so it will be recognized to humanoid without any modification.
Using as AnimationLibrary
- New inherited scene, or add to scene & check
editable children
- select
AnimationPlayer
- Animation > Manage Animations...
- click floppy icon > Make Unique > Save as
ALSMotionLibrary.tres
- load from another AnimationPlayer
Closing
I've thought that it's hard to use assets distributed for UnrealEngine/Unity in Godot, but meshes or animations are just a resource and expoting them can be automated in part by scripting.
This time I tried exporting from UE to Godot, and some techniques are useful for other engines too.
Issue
Some engine-specific assets (like Blueprint, C# code, etc) are hard to export.
Other exporting methods are required (manual port, develop transpiler?), but it's too hard to do soon.
I'll try them someday.