Content and Documentation for Customizable characters using FSkeletalMeshMerge

Hey everyone,

I just visited the Ue4 roadmap on Trello and I was surprised that I didn’t see a node for “Customizable Characters using FSkeletalMeshMerge and Texture atlases”. I hope you find this post useful and I will be most grateful for your support! Please reply if you want to see content examples, documentation and videos.

Customizable Characters using Mesh Compositing Advantages explained:

50 draw calls! ( this is ideal for multiplayer games!)
For multi player games,Mesh compositing (using FSkeletalMeshMerge) is the better choice for customizing characters. In example, if you have a multiplayer game where many people have unique armor, each component mesh of the character(helm,chest,arms, pants for instance) is combined and the engine only has 1 draw call. So, if you have 50 characters on the screen, the meshes are only 50 draw calls.

Versus

250 draw calls! ( this is not good for multiplayer games!)
The other option for customizing characters doesn’t appear to be efficient for multiplayer games. The other option is adding all the meshes into blueprints as components. Each component mesh as a draw call, so if you had 4 pieces of armor and 1 body mesh, this would be 5 draw calls just for the meshes! For 50 players, this would be 50 players x 5 meshes each=250 draw calls!

I’m really hoping the community is interested as much as I am, since I haven’t seen any marketplace content, documentation or videos on FSkeletalMeshMerge.
I hope you have found this post useful and I will be most grateful for your support! Please reply if you want to see content examples, documentation and videos!

Have a good day

I’d be interested in this.
my UDK game’s characters are composed of 9 body part meshes + a variable number of cloth and armor (anything from 2 to 10), and they are all using one ParentAnimComponent (same skeleton). when the time comes to make the move to UE4 I’ll most likely implement multiplayer, or at least a much larger amount of AI characters on-screen.

I’m curious as to how this would affect Morph Targetting though. ideally my head meshes will have morph targets but the rest wouldn’t. still if I could merge all meshes excepting the MorphTarget’d mesh it’d be huge.

I also wonder if it’s as good and great as you describe it. on paper you could reduce the drawcall amount… but only if all the meshes use the same materials. a single mesh with 2 different materials already produces 2 draw calls, so how does merging 2 skeletalmeshes with different materials (ie. body and armor) reduce the drawcall amount? all I see is it would reduce the processing time for the skeleton transform, but maybe I’m missing something?

Hey ,
1 Mesh and 1Material are 2 different draw calls no matter what you use. FSkeletalMeshMerge uses texture atlasing, from what I gather, this would be optimized from using regular multiple materials as well.

If anyone is familiar with UE3’S MODULAR pawn documentation, you may note that it never went into depth about how animtrees operated with each separate skeletal mesh. Making a blended animations were required for each piece of the armor. With FSkeletalMeshMege, this would be simplified greatly with only one mesh!

Your numbers don’t quite add up, in your example it’s 50 draw calls vs 250 draw calls :slight_smile: So you have saved 200 draw calls, but you have added a lot of complexity to your pipeline. All character and armor meshes now have to use a common base material. You have to be very specific about UV layout, and features like morph targets or material parameters are harder to use.

There are certainly cases where mesh merging is helpful or even necessary, but we feel for a lot of games, the better tradeoff is to use multiple skeletal components. We do want to have some good examples or tutorials on that, and we are discussing here quite what we want to do. Once we have that covered, we probably will try and cover merging, but for the reasons mentioned above, it is a little lower priority.

Have you tried using the existing FSkeletalMeshMerge code?

1 Like

Hello !
Thank you for taking the time to respond, I know you are very busy working on UE4 and I appreciate your time. You are doing a Fantastic job, the engine is unreal!

Just a heads up, I really value your post, I was merely trying to see if other “users” were interested. I realize using mesh compositing is the more difficult path, but it obviously has it’s trade offs. I was not aware that morph targets and material parameters were effected. Yes, I agree that Adding components has a faster development time (exponentially) and it’s easier to understand.

Can you please briefly describe why using morph targets and material params with FSkelMeshMege is more difficult? How are animations effected?

I am really looking forward to the customized character documentation that you speak about above :), great work so far! thank you for all that you have done on UE4, it’s really a fantastic piece of art (it’s unreal!).

Have a great night.

P.S.
I’ve corrected the math typo above,(it should have been 50 vs 250).

Material parameters are hard because you have to apply one MID to the whole mesh, which means you need multiple mask textures if you want red gloves and blue trousers. If you have multiple components, you can have one MID per piece, which makes it easier to modify colours etc.

Morph targets are tricky because they map to vertex indices. You would need to add an additional step to duplicate the morph target data when you merge the meshes and remap the verts to the new target mesh. That code doesn’t exist yet.

1 Like

actually I’m quite familiar with UE3’s modular pawn system, and I know that animating multiple parts was very easy. the only requirement was that the skeleton for all parts was exactly the same in your 3d package

my workflow was like this: rig and skin all of the body parts together (only done once) using 3dsmax’s Skin modifier (using envelopes, not painting vertices). for every new cloth/armor part, put it on top of the main model and copy-paste the Skin modifier. export. done.

since UE3 allowed the use of a ParentAnimComponent only the first body part needed an AnimTree assigned, while all the others would use the one from the first one via the ParentAnimComponent property

: does this then mean that atlases are not created automatically?

I find merging meshes to be way better than a modular pawn because the shadow outlines arent separate like they are when having multiple SkeletalMeshComponents, and its probably much more performant (other than at load time when the merging occurs) because there’s only one SkeletalMesh being animated/rendered (I don’t know what they are talking about texture atlases and stuff, you can have multiple materials per SkeletalMesh !)

Here’s the code for a component which has an editable SketetalMesh piece list (in the editor), and generates the mergemesh on creation time:
.h :


#pragma once

#include "CompositeModelComponent.generated.h"

/** Component that contains multiple SkeletalMeshes as a single unit */
UCLASS(editinlinenew, meta=(BlueprintSpawnableComponent), ClassGroup=Rendering)
class UCompositeModelComponent : public USkeletalMeshComponent
{
	GENERATED_UCLASS_BODY()
private:
	UPROPERTY(EditAnywhere, Category = "Pieces")
	TArray<USkeletalMesh*> PieceMeshes;

	void OnRegister() override;
	void OnUnregister() override;

	void CreatePieceComponents();
};


.cpp:



#include "CompositeModelComponent.h"

//////////////////////////////////////////////////////////////////////////

UCompositeModelComponent::UCompositeModelComponent( const FPostConstructInitializeProperties& PCIP )
	: Super( PCIP )
{
	PrimaryComponentTick.bCanEverTick = true;

	SetCollisionProfileName(UCollisionProfile::BlockAllDynamic_ProfileName);
}


void UCompositeModelComponent::CreatePieceComponents()
{
	if (GetOwner() == nullptr)
		return;

	if (PieceMeshes.Num() > 0)
	{
		TArray<USkeletalMesh*> mergeMeshes;
		mergeMeshes.Empty(PieceMeshes.Num());

		for (int32 i=0; i<PieceMeshes.Num(); i++)
		{
			if (PieceMeshes* == nullptr)
				continue;

			mergeMeshes.Add(PieceMeshes*);
		}

		if (mergeMeshes.Num() > 0)
		{
			USkeletalMesh* targetMesh = ConstructObject<USkeletalMesh>(USkeletalMesh::StaticClass(),this,FName("MergedMesh"),RF_Transient);
			TArray<FSkelMeshMergeSectionMapping> sectionMappings;
			FSkeletalMeshMerge merger(targetMesh,mergeMeshes,sectionMappings,0);
			const bool mergeStatus = merger.DoMerge();
			check(mergeStatus == true);

			this->SetSkeletalMesh(targetMesh);
		}		
	}
}

void UCompositeModelComponent::OnRegister()
{
	CreatePieceComponents();
	Super::OnRegister();
}

void UCompositeModelComponent::OnUnregister()
{
	Super::OnUnregister();
}


Please note, that the FSkeletalMeshMerge thing supplied with UE4 identifies materials on the input meshes by their UMaterial*, so make sure you have a default material properly set on all the source SkeletalMeshes, otherwise the output MergedMesh will be all the same material (as all input UMaterial* are nullptr). I think this is a bug and should be fixed (it should identify by source material ids, increasing for each source piece, this would make the output material list in a predictable order as well).

FSkeletalMeshMerge hmmm what if you don’t use C++ is there another way around it?

You have some points here, actually, I already done some of the lines of the codes in my past programs.

1 Like

You can use the ‘bLightAttachmentsAsGroup’ property on the parent component to shadow it and all attachments as one group, which will prevent the shadow artifacts (and improve performance). You can use the ‘SetMasterPoseComponent’ function to only animate one ‘master’ skeletal mesh and have others just use its animation. The main reason for merging meshes it to reduce section count in your scene. If you don’t combine textures when you merge, you won’t actually be reducing your section count. 1 mesh with 5 materials or 5 meshes with 1 material each are both 5 ‘draw calls’. I hope that helps clarify a bit!

Also, my code forgot to set targetMesh->Skeleton ref to one of the source meshes’ Skeleton. Without this, it won’t play any animations.

Hey so for anyone interested I created a plugin for merging meshes as in the ue4 docs the code for doing so is kind of outdated if you are interested you can download the plugin from my github as for now for ue4.21

Here is the link:

One problem I haven’t been able to take care of is the matter that when one of the body parts is a cloth part it won’t be simulated as cloth after merging together.
If I get any updates on this I will inform you.

Kind regards
Luis

Sorry to revive an old thread but i did a merge in and for some reason our sockets fail to work. None of the weapons attach after the merge operation
?..

Dark583, You are the only other person I’ve come across who has also had this issue. Did you ever figure out how to fix it?

No we ended up going another route, are you having the issue as well now?

That issue seems to be gone, I can attach stuff to bones.

It would be great to make animation blueprints work with merged meshes. I would happily try it, but maybe anyone knows that it’s not possible already?

**UPDATE: **I’m getting random crashes at BoneContainer.cpp:79. That feature looks untested, I think I’ll try something else. Sad.

Maybe this solve your problem. It solved mine:

Add these to the end of the merger cpp:

BaseMesh->RebuildSocketMap();
return BaseMesh;

Solution came from “BearInATie”