Replication of Character Ref in Player State

I think I’m improperly using a reference to the player character inside the player state to replicate character customization.

In the player character BP I created material instances.

I created an actor component, named it character customization, and added it to my player state BP.

In the character customization component I added a replicated reference to the player character, and rep notified colors.

In the player controller on possession I get the player character and set the player character reference in the character customization component.

When the player spawns colors are pulled from the saved game and set on the server in the character customization component.

On rep for each color I get the character reference, the appropriate material instance, and change the color.

Everything works great until I spawn in the host, run far away, and then spawn in the client. The host’s custom colors never show, even if the client runs over to the host.

I tried setting the character BP to always relevant just to test culling and that didn’t help. I checked the validity of the character ref in the character customization component, and that is returning false for the host when the client spawns far from the host, but true when the client spawns near the host.

So it still seems like a culling distance issue, but maybe it’s actually a timing issue? Is there a better way to reference the character from the player state? Or is there a better way to reference and change the color of the material instances following the rep notify of the custom colors?

I think the issue is caused by network relevancy and replication timing. The PlayerState is replicated to all clients but the player character is only replicated when it becomes network relevant. So, when the client spawns far away, the host’s character might not exist on the client’s side yet. The customization color data arrives but the character reference is invalid, so the colors aren’t applied. When the character eventually becomes relevant, the OnRep doesn’t run again because the color data hasn’t changed.
Moving the character customization component from the PlayerState to the player character would be a good idea. You can keep the customization color data in the PlayerState but let the component on the character handle applying those colors to the materials.

That makes sense. How would I trigger a color update within the character though if the character reference isn’t yet valid in the player state? If I could just get the character ref or “get controlled pawn” within the on rep function for the color, but the character isn’t valid. Or do I need to send the color to the character outside the on rep somewhere?

With the customization component moved to the character, the PlayerState doesn’t need to trigger the update. Once the client gets close enough, the character becomes network relevant and gets replicated. Since the customization component is now attached to the character, it can use GetOwner() to access the character/mesh/material and apply the color.

That did it! I was using a structure in my customization component to hold all the colors. I just added the same structure to my character and had it RepNotify. Then I set that character’s structure from the player state’s RepNotify for the same structure and handled all the changes to the character from the character’s RepNotify.

Use a repnotify in the character class. Have the onrep function apply the change.

You can take a local call from client and pass it up the controller to the GM or Server proxy. Apply it there and it will replicate. Join, late join, rejoin, ncd changes etc.

Players outside ncd are destroyed on the client. When they come back in they get rebuilt with a fresh updates of states and rep VALs.