[4.6.1] Set Is Replicated causing StaticMeshComponent duplication

Hi,

I will describe steps I did which led me to this issue (using blueprints):

  1. Set actor blueprint property Replicates to true.

  2. Set value of Should replicate in SetIsReplicated node to true on Event Begin Play for first StaticMeshComponent (actor has a StaticMeshComponent by default in its blueprint).

  3. Dynamically add second StaticMeshComponent during runtime to an actor.

  4. Set value of Should replicate in SetIsReplicated node to true for added StaticMeshComponent.

  5. There are now three Static Meshes rendered in actor.

Does anybody know if this is an issue with a solution or is this simply an engine bug?

Hi ,

Please attach a screenshot of your BP setup so we can attempt to reproduce this here. Thanks!

As my blueprint is somehow big (about 500 nodes) here are screenshots of crucial pieces of it:

29017-screen+shot+02-05-15+at+01.46+pm.png

Before this set of nodes there is a Switch Has Authority node and execution pin comes out from Authority:

Array Initiation:

Set Transform of Static Meshes:

StaticMesh1 is starting StaticMeshComponent.
DeltaRELCombine is calculated relative vector determining where new StaticMeshComponent should be added.
StaticMeshComps is an array of references to StaticMeshComponents in actor.
Other variables are not important for this issue.

I’m not able to reproduce any extraneous meshes. Where is third mesh component being rendered, and what are you doing to detect it? When I set up something similar to this and use GetAllActorsOfClass to get all static mesh components, I only get two.

Are you able to reproduce this in a new project, or only your current project? If you can reproduce in a new project, please upload it somewhere like Dropbox and send me a link so I can look into it further.

Also, out of curiosity, why are you trying to replicate a Component of an already replicated Actor?

Thanks!

I think there is actually no third StaticMeshComponent, but because of some issues with dynamic material instances it is rendered.

On server meshes become colored in green and red in some places when they enter a certain volume. This effect is not replicated on client and is actually a desired outcome, but I don’t know why client does not see change in dynamic material paramaters as script is launched both on server and client. After addition of a new StaticMesh client suddenly starts to render a colored StaticMesh placed in same location which original StaticMesh component was located, however, simultaneously it renders real server result in an uncolored version.
Here are some screenshots depicting issue:

-Server (Player 1)-

Before entering volume

In volume before addition

In volume after addition

-Client (Player 2)-

Before entering volume

In volume before addition

In volume after addition

Also, out of curiosity, why are you trying to replicate a Component of an already replicated Actor?

This is because when I set Replicates property to true and do not set Should Replicate to true on every StaticMesh added, I cannot see any new static meshes on client at all - nothing happens.

I created another project to check some situtations similar to this one and stumbled upon a slightly unexpected effect.
I made an event launching every 2 seconds, which adds a new StaticMeshComponent at a random location. I enabled Replicates property, but did not do anything with Should Replicate property of StaticMeshes this time.
thing is, when I connect nodes in event to Authority in Switch Has Authority node, added Static Meshes are only visible on server. However, if I delete Switch Has Authority node, so that script runs both on server and client, are two StaticMeshes added every 2 seconds.
second situation is explicable as script runs twice - first on server and on client what gets replicated to each other.
I do not understand first situation. If actor is set to replicate and script runs on server, why client is not able to see outcome?

Okay, I think I need to look at project, as there’s a lot going on here and a lot to check. If you can set up a test project that displays this behavior, that would be very helpful. I think it may be a bug that a newly added component does not maintain Replicates property of Actor, though I’ll need to check into that to be sure it isn’t expected behavior. I asked about why you were trying to replicate mesh on an already replicated actor because it seems like it’s first thing you’re doing in your initial description, before you add any new meshes, and that seems redundant to me.

Download TestProject
Here is a tiny project depicting issue. Authority check is necessary in both this project and original one as nodes must be strictly executed on server and then replicated to clients.

So in this test project, initial cube is replicated as expected, because Actor is set to Replicate in its defaults. Switch Has Authority node is making it so only instance of this BP on Server is adding StaticMeshComponents, so those won’t show up on Client. If you then SetIsReplicated to true for components, those components will also be replicated. This works as I would expect it to.

If you delete SwitchHasAuthority node while Replicates is set to true, instance on Server is replicating code on Client, so Client will see both its own added static mesh and another added from Server (though it won’t be at same location, it’ll be at its own random location). This is probably what you were seeing initially.

best way to get this working way you’d like, where Blueprint exists in level at start, and spawns a new static mesh component on server and replicates that to client, is to have Replicates set to True, Switch Has Authority for random generation, and then SetIsReplicated to True for added meshes.

So in this test project, initial cube is replicated as expected, because Actor is set to Replicate in its defaults. Switch Has Authority node is making it so only instance of this BP on Server is adding StaticMeshComponents, so those won’t show up on Client. If you then SetIsReplicated to true for components, those components will also be replicated. This works as I would expect it to.

If you delete SwitchHasAuthority node while Replicates is set to true, instance on Server is replicating code on Client, so Client will see both its own added static mesh and another added from Server (though it won’t be at same location, it’ll be at its own random location). This is probably what you were seeing initially.

best way to get this working way you’d like, where Blueprint exists in level at start, and spawns a new static mesh component on server and replicates that to client, is to have Replicates set to True, Switch Has Authority for random generation, and then SetIsReplicated to True for added meshes.

Thanks for insight, however, solution you provided is exactly what I have done in beginning (see first post) and result is depicted with screenshots I uploaded in one of comments:
-Server (Player 1)-

Before entering volume

In volume before addition

In volume after addition

-Client (Player 2)-

Before entering volume

In volume before addition

In volume after addition

I’m not seeing anything like that. Can you update test project so it reproduces this behavior?

test project does not contain actual algorithm I use in my original one, it presents only concept. As I said original one is slightly complex and it would most probably take me days to strip it down. There are some graph algorithms, adjecency matrices of Static Meshes implemented whilst event graph is currently very poorly commented.
I tried a slightly different approach and outcome puzzled me even more.
I deleted Set Is Replicated nodes and here are steps in blueprint:

  1. addition event launches on server
  2. crucial values for addition are calculated on server.
  3. After calculations, another event set to Multicast is called and executes both on client and server - it adds StaticMeshComponent using replicated values calculated on server.
    It seemed like a good idea, but here is result:

Server:

Client

weirdest thing is that when I actually debug location values for StaticMesh Components on client (which are not replicated in this method), it outputs proper values being same as those on server. As you can see, in visual manner StaticMeshes on client are completely incoherent.

I managed to resolve issue by getting rid of Set Is Replicated nodes and making variable of DeltaRELCombine (one which is set after calculations and determines where new StaticMesh should be placed) RepNotify. In On Rep function I implemented StaticMeshComponent addition so that it executes both on client and server in same way.
I also had to play with dynamic material instances a bit as they where replicated only upon some significant events.

Thank you very much for your support :slight_smile: