How can I play animations strictly from C++?
I see this asked a lot here but never fully answered. I've asked similar questions before. Here are the ground rules:
We have: Montage_Play(anim, play speed), and Montage_JumpToSection to skip ahead.
I can't see a way to blend 2 (or more) animation together from C++; alternatively, a way to play a Blend Space (1D or 2D) from C++.
I can't see a way to play an animation into a particular slot from C++ (eg, Upper body or Lower body). Playing a Montage that is not set to slot "Full Body" or "Default" results in not playing at all.
I can't see a way to play an animation to the end and stopping there (i.e. not looping the animation). I could add a bunch of logic to do manage this, but animation systems normally have this in there somewhere.
If it's not possible, I'm fine with that as an answer. If you're curious about why I would not want to use the editor features for these things you can read the following but if you're not curious then you can skip the rest of this paragraph. I've been developing games for many years now and am very comfortable with C++ implementations. IMO, the animation part of the editor is bad for game development. Having two competing and unrelated state machines (one for behavior and one for animation) battling for control over a character is an ill-conceived concept. Both developing complexity in their own unique ways (state machine vs behavior tree or other) while trying to keep it in sync and tracking lines of causality is crazy house. Bugs are invisible, systematic and display emerging behavior (the perfect storm of development pain). It's fine if you're a student trying to learn 3D but for complex professional work, specially dealing with complex animations, it's a non-starter.
asked Aug 27 '15 at 10:51 PM in C++ Programming
Playing Blend Spaces from C++:
The example used is with a 1D Blend Space, but it will also work for 2D or 3D blend spaces :)
To Play an animation in a slot:
To Play a simple full body animation and stop at the end:
Where MyAnimTimer is a float, and PauseMontageTimerHandle is a FTimerHandle.
To Play a simple full body animation and jump ahead to a section. Montage_Play(anim, play speed) and Montage_JumpToSection.
To Play an animation additively use the PlaySlotAnimationAsDynamicMontage function as before, into a slot set up like this: https://docs.unrealengine.com/latest/INT/Engine/Animation/AnimHowTo/AdditiveAnimations/index.html
Ok, Adding some of the basics that might trip some people up
a) Declare your montage variable in your header file:
b) In the constructor, load the montage:
c) Play the montage as before
@rantrod This is the best answer so far to play an animation but I'm wondering, why it is so awful hard to do in just C++. Even this example uses blueprints. Each time a programmer asks for plain C++ examples, the response is that blueprints are superior.
For some jobs they are not. I'm developing procedural animation for a different engine and would like to see just a simple -complete and working- example how to play animation in Unreal inside the editor (in Edit mode - not in Play mode).
answered Jun 13 '16 at 12:34 AM
Thank you so far, In a simple coding world this would be straight code and would work ( It does not)
I apologize for barging in, but as this thread comes up in searches, I thought I should chime in with what I learned through trial and error. The example below is not complete, but should help pointing in the right direction, hopefully.
There is a minimum required tinkering with non-C++ blueprints, but in my approach I tried my best to "set it and forget it". If there are better ways, please share :)
This is how my montage looks like, just two empty slots, I handle their population through C++
this is how my anim graph in my custom animation instance looks like
Inside each state machine I connected a dummy empty state to the entry point, not shown in this picture, but you get the gist of it.
This is my C++ code snippet to handle fetching animation sequences on the fly and assign them to the montage slots. please note that I'm using some custom functions I wrote that are not shown in the code below
as I mentioned, the example above is not either complete or fully functional out-of-the-box, but hopefully should help...
Follow this question
Once you sign in you will be able to subscribe for any updates here