How to use EMotionFX with C++?

I see that in Lua, we can use EMotionFX like this

    AnimGraphComponentRequestBus.Event.SetParameterFloat(self.entityId, self.movementSpeedParam, self.characterSpeed);
-- Update the anim graph to attack or jump
AnimGraphComponentRequestBus.Event.SetParameterBool(self.entityId, self.attackParam, self.shouldAttack);
AnimGraphComponentRequestBus.Event.SetParameterBool(self.entityId, self.jumpParam, self.shouldJump);

In the Gems’ code, EMotionFX can be used like this (found this in the SpeechComponent)


#include <Integration/AnimGraphComponentBus.h> //Can't include this into my project?
EBUS_EVENT_ID_RESULT(parameterIndex, m_entity->GetId(), EMotionFX::Integration::AnimGraphComponentRequestBus, FindParameterIndex, "visemeIndex");
EBUS_EVENT_ID(m_entity->GetId(), EMotionFX::Integration::AnimGraphComponentRequestBus, SetParameterFloat, parameterIndex, (float)anim->GetVisemeIndex());

But I can’t find a way to include the header file: <Integration/AnimGraphComponentBus.h>. Do I need to do extra things? (I’m coding in the default C++ empty project generated by Lumberyard)

Thanks.

So I figure it out.

First, we need to add EMotionFX as dependency for our Gem.

Then use this code


#include <Integration\AnimGraphComponentBus.h>
void GemName::Activate()
{
EBUS_EVENT_ID_RESULT(m_playerData.walkParam, m_PlayerComponentID, EMotionFX::Integration::AnimGraphComponentRequestBus, FindParameterIndex, ANIM_WALK);
}
//Somewhere in your code, you can manipulate walk param
bool bIsMove = !m_vPlayerVelocity.IsZero();//walk param is bool type
EBUS_EVENT_ID(m_PlayerComponentID, EMotionFX::Integration::AnimGraphComponentRequestBus, SetParameterBool, m_playerData.walkParam, bIsMove);

Thanks for sharing informative post admin, keep up the way you solve problems.

Cms Website Development Services