Problem with mesh replication

Hello,

I’ve been fiddling with skeletal mesh replication for a week now and, although I have searched everywhere, I cannot seem to find a way to make it work. If anyone is able to help it’ll be very much appreciated, I’ll attach some screenshots with my setup below.

immagine

This is on the begin play of my character. The variable UserData just contains some info on which meshes to use for each body piece.

This sets the 3 other Skeletal Meshes’s position to match the main one.

First part of “SetAppropriateMeshes” function (just getting data out of my containers).

This is what happens in the true side of the branch, its missing 2 rows but they are identical to the last one, they just set different meshes. The false side does the same but for female parts.

These 2 do the exact same thing, one for Skeletal Meshes and the other for Static Meshes. They run on the server.

This is the one for Skeletal Meshes, and it just sets the values of the mesh references i have in my character so that they can be RepNotified.

immagine

In the RepNotify functions this server event gets called. It’s the same for every RepNotify function that deals with Skeletal Meshes, and another version that deals with Static Meshes.

The Server then calls CLIENT_SetSkeletalMeshes (Or static), which is a Multicast Event, and then sets the Mesh itself.

The Client version just sets the Mesh for whatever Client received it.

The main problems I’m having are that:

  1. When a second client logs in it sees the first client as if it still had the base body while the first client seems to receive the correct visuals
  2. When I test it in engine, it seems that on the second clients viewport the first client’s pawn gets duplicated

Thanks to anyone who can help!

Skeletal mesh doesn’t replicate. The way I’m doing it on a modular character is to have the server execute a multicast → Rep_Notify. The rep_notify function builds the mesh and sets it.

Thanks, I’ll try it tomorrow and see if it solves the problem!

I found a tutorial on Skeletal Mesh replication and this fixed my setup which is similar to yours albeit less complicated (Thanks for the suggestion RevOverDrive, but the rep notify didn’t make a difference for me).

And FYI, I’ve got my Mesh randomization happening in the GameState so I can be sure that it’s accessible by all players, but in my case, it’s just because I wanted randomization with removal so I couldn’t keep the array of skeletal meshes inside the character. I just wanted to mention it in case you might be trying to execute the code in the wrong place.

And for Posterity in case the YT video disappears in the future; this is the key:

1 Like

Oh snap! I jumped the gun thinking my issue was solved because I accidentally ran Standalone when I thought I was set to be a Client. So I’m with you, this code isn’t working for me either even though it should. For whatever reason in my case it’s assigning the same mesh to every A.I. in MP.
I’ll look at it again tomorrow. Maybe one of us will figure it out and help the other :stuck_out_tongue:

1 Like

First off, Run on Server Events actually use switch has auth internally, so no need to use it here. Only the client event needs to.

Second, Setting the mesh should happen in the On_Rep function.

Server Event → Multicast → Set the On Rep variable…
OnRep_function → Build the skeletal mesh.

I’m using mesh merge. My On_Rep var is the Mesh Merge Parameters. In the docs example they are using Begin Play where I use the onrep_function.

Added benefit here is late joiners and those just reaching netcull distance will see the correct mesh.

Right, I did hear that’s the reason to use RepNotify because Multicast only works when clients are relevant to you at the time of the change. Okay, I’ll try a notify again. It doesn’t matter what the notify is right? I can just use a simple bool and set it to on when I want the change to happen? I think the reason I thought it didn’t work the first time is probably because I didn’t have the code setup properly to begin with. Thank you for your suggestions, I appreciate the help.

Okay, I’m getting really confused. If I set it up like this:

The server has authority the entire time so the Repnotify is never called because at each Switch it simply ends the execution. If I remove the Switch Has Auth, the RepNotify is called and all of my AI have no Skeletal mesh assigned. I’ve checked the NewMesh by getting the display name and it is unique, but for whatever reason when I call the Repnotify there’s no mesh assigned.

I don’t understand why you have to do this on the server and the client at the same time. Shouldn’t the server be the one getting the info and then it simply passes that info along to the clients when you request it with a notify or multicast? This doubling up on code seems totally redundant. The whole point of a Multicast is that it happens everywhere. Server and Client. So why on earth would you need to do it on server and then multicast? Multicast should be doing it in one step (and according to my print strings, it is).

And that was the solution!

In my Game State I turned my “Get Random Mesh” events into Multicast events.
Then in the AI, I stripped out all the extra “on server junk” and just used a Multicast to get the mesh and set the mesh and then called the Repnotify and it works!

Thank you for the help RevOverDrive! I really could not have figured this out without you!

Yosef, I hope this helps you too!

For the sake of discussion here’s some snippets from our prototyping test phase.

Blue section is called off Begin Play in the Character class. We do this so that on level load and character spawns there’s a mesh. Although naked/base model…there’s a fully replicated mesh.

Client is loaded, so we call SRV Revs MeshMerge. This executes Revs Mesh Merge function.

The delay is to simulate MP delays. It also gives you debugging time.


This function builds an array of parts for Mesh Merge, Merges, Validates the Merge, then calls a Multicast ( Srv Multicast Skeleton img 1). Note the Mesh Merge return is passed to the multicast.

Srv Multicast Skeleton event sets w/notify Merged SK Mesh.


Thanks @Rev0verDrive and @TorQueMoD

I’ve managed to make it work, in the end I chose to set up RepNotified mesh variables since I read that merged skeletal meshes don’t support morph targets out of the box and we plan on using them quite heavily.

This is the final setup for now:
This gets called when the character appearance is selected…
immagine

…which then calls this…
immagine

…this then finds the correct meshes and then calls this…
immagine

…which in turn sets the variables with Notify.

The RepNotify functions are then used to set the skeletal meshes
immagine

Thanks again, have a nice day/night!

1 Like

I just wanted to post this here for anyone in the future:

I had to re-do my code because of an update to a marketplace asset that I’m using, but when I did so my prior solution stopped working and I couldn’t understand why.

Today I realized that the fix is really simple. Sometimes you need to add a delay between getting your mesh and applying your mesh to give the system the time it needs to execute things properly. In my case I have the selection of which mesh to use happening as a Server Event inside the GameState. Then as each AI is spawned, I get the SelectedMesh from the GameState and then use a RepNotify to update the skeletal mesh for all players.

RandomizeAIMesh03 - AICharacterRepNotify

My code was actually set up correctly, but each AI was being assigned the exact same mesh and I couldn’t fathom why because I knew my code should be working. Then I added a delay of 0.2 seconds between Getting the Mesh inside the AI and Randomly selecting a mesh in my GameState and this fixed the issue.

The reason this fixed the issue is because the the GetMesh code was firing at the same time as the Random selection, so that specific code didn’t have enough time to execute multiple times. By adding the delay of 0.2, it gave the ranomization code time to execute and fixed the problem!