Replication on SkeletalMeshes

As far as I know, components never replicate. You’ll need to write a function to broadcast mesh change, called by the server.


	UFUNCTION(NetMulticast, Reliable, WithValidation)
	void SetMeshBroadcast (USkeletalMesh* NewMesh);


bool AShooterCharacter::SetMeshBroadcast_Validate(USkeletalMesh* NewMesh)
	return true;

void AShooterCharacter::SetMeshBroadcast_Implementation(USkeletalMesh* NewMesh)
	if (Mesh)

Hello, I’ve hit a bit of a wall when trying to implement a character which changes skeletalmesh on the press of a button, so I figured I would try to ask here! I’ve so far modified the shootergame code as a base.

So far I’ve made it work by having several SkeletalMeshComponents and making them invisible/visible depending on the conditions I’ve set and while it seems wasteful to have all those components just lying around waiting to be used it works for now, clientside anyway.

The problem is that any meshcomponent apart from the original one does not replicate properly to other clients, showing up even though it’s supposed to be invisible, does not animate to other players and/or crashes.

So what I’d like Is to either:

  1. Is there a way to change the character’s mesh in code (or in blueprints, so long as it replicates to all other players. I’ve seen that there are some problems with replicated blueprints) while pointing to an object in the asset browser? Or perhaps a similar way.

That way I wouldn’t have to have multiple skeletalmeshcomponents lying around, toggling their visibility when required, but rather only change the mesh in the code when required to do so. If possible, could you write a very basic way to do so within a function? I noticed there was a Mesh->SetSkeletalMesh function, but I was unsure of how to use it properly.

2 If not possible, what is the requirements for making a skeletalmesh replicatable? My declaration for one of the meshes is as follows:

UPROPERTY(VisibleDefaultsOnly, Replicated, Category = Mesh)
TSubobjectPtr<USkeletalMeshComponent> MeshFire;

I added the Replicated part in the character header and in the cpp I added

DOREPLIFETIME_CONDITION(AShooterCharacter, MeshFire, COND_SkipOwner);

Toward the bottom. I tried without a condition but then it crashed due to the mesh being Null when the second player spawns for some reason. Maybe there’s an underlying problem if the replication is in fact correct?

Either way, solving the first problem would probably be easiest and best in this case, hopefully someone out there can enlighten me!

#Easier Solution

You’ll have a much easier time of you simply possess a new character to put in place of the previous one.

Many due to changes in collision and animation complications, since it is the Character BP that stores the AnimBP, and the Anim Instance may or may not be updated / recreated for the new skeletal Mesh

Replicating the Character change is something I’ve already done in my own game,

though in my case I wanted it to be flash, you could make it more subtle if you wanted to!

Epic Wiki Link To Video


PS: all of this just my opinion, showing you an alternative

Hmm, interesting. I will look into it later but it seems like it could be useful!

That’s true, I hadn’t thought of that. So yeah, possessing a new character seems like a better alternative.

The way I see it then is basically copy all of the code from the ShooterCharacter cpp and h files into a new file for each character and have the playercontroller posess the new character somehow, either through blueprints or code? Care to elaborate a little bit on that? :slight_smile:

I used this method as it was indeed the easiest. I did it using blueprints though so in terms of code I’m not able to provide any more help than that, but creating a new pawn and possessing it using the playercontroller was the way I did it