How to play animations by code?

You’ll want to make your own state machine. A series of booleans called via tick. If you want a better idea of this download the Paper2D C++ module and give that a look at.

I think it has something like UpdateAnimation();. So from there you can get an idea on how to make this work.