These scripts enable you to play smooth 2D/3D Unity animations in Python.
It is particularly useful when you need to animate window elements, create GUI effects, or preview Unity animations outside the Unity Editor.
- Parse and play Unity
.animfiles in Python - Support for Position, Rotation, Scale, and Euler curves
- Full Hermite spline interpolation with weight support
- Animation event system with callback registration
- JIT acceleration with numba for high performance
- PySide6 integration for real-time GUI animation
- Interactive debugging panel with real-time parameter adjustment
- Multiple output formats (Pygame, PySide6, QML)
Run the example selector:
python example.pyAvailable examples:
interactive_panel- Interactive animation debugging panelpygame_viewer- Pygame-based animation viewerpyside_popup_window- PySide6 popup window animationqml_window- QML animation window (ball animation, button scaling)
fromunity_animation_playerimportAnimationPlayer# Load animationplayer=AnimationPlayer("examples/AnimationClip/T.anim")
# Get animation state at 0.5 secondsresult, valid=player.play_frame(0.5, path="general")
ifvalid:
print(f"Position: {result.get('position')}")
print(f"Scale: {result.get('scale')}")
print(f"Rotation: {result.get('rotation')}")Control animation output with flexible parameters:
# Map Unity coordinates to screen coordinatesresult, valid=player.play_frame(0.5,
position_unit=('x', 'y'),
position_ratio=(19.2, 10.8), # Scale X and Y independentlyposition_reverse=(False, True) # Reverse Y axis
)fromPySide6.QtCoreimportSignalfromunity_animation_playerimportSignalAnimationPlayerclassMyWindow(QWidget):
anim_signal=Signal(dict)
def__init__(self):
super().__init__()
self.player=SignalAnimationPlayer(
self.anim_signal, "animation.anim"
)
self.anim_signal.connect(self.on_frame)
self.player.play()
defon_frame(self, data):
ifdata.get('playable'):
pos=data.get('position')
self.move(*pos)Register callbacks for Unity animation events:
defon_event(data, float_param):
print(f"Event: {data}, {float_param}")
player.register_event('eventTriggered', on_event, ('data', 'floatParameter'))- SHA256-based JSON caching for fast reloading
- Numba JIT compilation for core interpolation
- PyYAML CLoader for fast YAML parsing
pip install unity-animation-playerWith optional dependencies:
pip install unity-animation-player[full] # Install all extras
pip install unity-animation-player[numba_acceleration] # With numba JIT
pip install unity-animation-player[with_signal] # With signal support (Qt)pip install git+https://github.com/LjcYounger/UnityAnimationPlayer_python.git- Python >= 3.8
- numpy
- PyYAML
- PySide6 (for GUI features)
- numba (optional, for JIT acceleration)
- Rational Bezier interpolation - Full Unity curve matching
- Weight mode support - Now fully implemented
- Independent axis control - Per-axis unit, reverse, and ratio
- Event time reversal - Events trigger correctly when playing in reverse
- Dynamic event addition - Add custom events at runtime
The initial version had limitations with weight mode support. The current version fully implements Unity's interpolation system, including weighted Bezier curves and proper handling of infinite slopes.
MIT License
Issues and pull requests are welcome.
Detailed Documentation in https://ljcyounger.github.io/UnityAnimationPlayer_python/