I have created a new C++ class character. However, I am not really sure how to attach a Mesh to it and an animation. Can someone please give me a detailed guide with the needed commands on how to do that using the Third person static mesh and animation?
Thanks in advance.
Take a look at the various example projects that ship with unreal. They show how to assign meshes, use sockets, use animations etc.
It would be more useful if you point out a certain example. The ThirdpersonCharacter example I can only find it in Blueprints. i.e. I can’t seem to be able to find a C++ equivalent to what the ThirdPersonCharacter Blueprint Event graph does.
I don’t have the samples installed at the moment, but I’m reasonably sure that if you go to make a ‘New project’ you’ll have a ‘Blueprint’ and ‘C++’ tab. Both should have the same sample projects so pick the C++ tab, select the ThirdPersonCharacter project and load it up.
In your Character class
// in YourCharacter.h
#include "Engine/SkeletalMesh.h"
#include "Animation/AnimSequence.h"
//select mesh in blueprint derived from YouCharacter class
UPROPERTY(EditAnywhere, Category="SomeCategory")
USkeletalMesh* SkeletalMesh;
//select animation in blueprint derived from YouCharacter class
UPROPERTY(EditAnywhere, Category="SomeCategory")
UAnimSequence* Animation;
UPROPERTY(EditAnywhere, Category="SomeCategory")
bool bLoopAnimation;
//in YourCharacter.cpp
//in BeginPlay() function
//Validate - important
if(!SkeletalMesh) { return;}
//Validate - important
if(!Animation) {return;}
GetMesh()->SetSkeletalMesh(SkeletalMesh);
GetMesh()->PlayAnimation(Animation, bLoopAnimation);