Download

Playing animations using Montage_Play

Hello, EU4 seems to have no way to play animation sequences, like UDK3 with “playcustomanim”. The only thing I’ve seen in the documentation is the use of montage.

I tried to do it and it works, but only in the main mesh. My pawn is modular, and the rest of the component modules omitted the animation. It’s possible to fix this?

I tried to apply the same animation to all modules, but don’t know how to access the childen modules.

For example to get Mesh Animinstance:

UAnimInstance* AnimInstance = Mesh->GetAnimInstance();

but for one of the component modules (Cloth1):

AnimInstance = Cloth1->GetAnimInstance();

guives the error: “Error 1 error C2065: ‘Cloth1’ : undeclared identifier”

How can access to Cloth1? It’s a childen of Mesh.

For modular characters you want to have one ‘master’ SkeletalMeshComponent which animates, and then multiple ‘slave’ components that inherit their animation. You use the SetMasterPoseComponent function on the child components to set that up.

Hi James, thanks for reply.

I have added the components using the character blueprint, but I dont see “SetMasterPoseComponent” in the properties. So I have wrote in the code, following this tuto: https://wiki.unrealengine.com/Modular_Pawn

Hi James, thanks for reply.

I have added the components using the character blueprint, but I dont see “SetMasterPoseComponent” in the properties. So I have wrote in the code, following this tuto: https://wiki.unrealengine.com/Modular_Pawn

But I have a error when compiling, this is my code:

GAMECharacter.h



class AGAMECharacter : public ACharacter
{
	GENERATED_UCLASS_BODY()

	/**
	*  The skeletal mesh used for the body.
	*  Mesh (inherited from ACharacter) will act as characters head.
	*/
	UPROPERTY(Category = Character, VisibleAnywhere, BlueprintReadOnly)
	TSubobjectPtr<class USkeletalMeshComponent> Body;

	/**
	*  Name of the BodyComponentName.
	*  Use this name if you want to prevent creation of the component (with PCIP.DoNotCreateDefaultSubobject).
	*/
	static FName BodyComponentName;

etc .....
}


GAMECharacter.cpp




FName AGAMECharacter::BodyComponentName(TEXT("CharacterBody0"));

AGAMECharacter::AGAMECharacter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	static FName CollisionProfileName(TEXT("IgnoreOnlyPawn"));

	Body = PCIP.CreateOptionalDefaultSubobject<USkeletalMeshComponent>(this, AGAMECharacter::BodyComponentName);
	if (Body)
	{
		Body->AlwaysLoadOnClient = true;
		Body->AlwaysLoadOnServer = true;
		Body->bOwnerNoSee = false;
		Body->MeshComponentUpdateFlag = EMeshComponentUpdateFlag::AlwaysTickPose;
		Body->bCastDynamicShadow = true;
		Body->PrimaryComponentTick.TickGroup = TG_PrePhysics;
		Body->bChartDistanceFactor = true;
		Body->SetCollisionProfileName(CollisionProfileName);
		Body->bGenerateOverlapEvents = false;

		// Mesh acts as the head, as well as the parent for both animation and attachment.
		Body->AttachParent = Mesh;
		Body->SetMasterPoseComponent(Mesh);

		Components.Add(Body);
	}


	// Set size for collision capsule
	CapsuleComponent->InitCapsuleSize(42.f, 96.0f);

etc...
}


And this is the error when compiling:



Error	1	error C2065: 'Components' : undeclared identifier	C:\Users\i7\Documents\Unreal Projects\GAME\Source\GAME\GAMECharacter.cpp	35	1	GAME
Error	2	error C2228: left of '.Add' must have class/struct/union	C:\Users\i7\Documents\Unreal Projects\GAME\Source\GAME\GAMECharacter.cpp	35	1	GAME


The only thing I’ve changed is “AMyCharacter” by “AGAMECharacter”. “Body” doesn’t exists in the blueprint, but I have tested with components that exists, and the same error.

What is wrong?

The tutorial you’re following along with seems to have been written from an older, beta build. The code is failing to compile because the “Components” array variable has actually been removed in the newer version of the engine. When you create components in the constructor as you’re doing with your code snippet, you no longer have to worry about adding it to a components array, you just have to make sure it’s assigned to a UPROPERTY, as you’re doing when you assign it to the Body variable. You can remove the “Components.Add(Body);” line entirely and it should compile.

Thanks Billy, by removing the “components.add” there are no error when compiling the code. But when setting a mesh to the component in the blueprint and try to play, the Editor crashes.

Do I have to remove or adding something else in the code?

Edit: seems to be one of the parameters in constructor, removing all works, I will find the causer and will post.

Edit: SetCollisionProfileName(CollisionProfileName); … without this works. Probably I haven’t that profile configured.

Thanks to all!

Hmm, glad that you’ve got your problem figured out, though that still shouldn’t crash. Could you maybe post on our AnswerHub so we can try to reproduce it and get the bug patched up? Here’s a post on how to report a bug: How do I report a bug? - UE4 AnswerHub

Here is it: Editor crashes while setting collision in a modular pawn - UE4 AnswerHub

the text formating hasn’t been too good…