Summary: Child Actor Components that are set to “Replicates” or “RepNotify” will create 2 copies of the component on both client and server (so 4 copies total) in a multiplayer game when the parent object is also set to “Replicates” or “RepNotify.”
Detailed Description (building): I have a building Actor (static mesh with collision box that is derived from Actor) that I want created and owned by the server. To meet this requirement, the server spawns the building using “SpawnActorFromClass” and the building class is set to “Replicates” so that the building is also created on the client when the server creates it.
Detailed Description (door): I also have a door Actor (skeleton mesh with 2 animation, box collision that is derived from Actor). The door has a Boolean parameter called “isOpen” that can be toggled with a mouse-click. The “isOpen” parameter is set to “RepNotify” so that when its open/closed state changes, it triggers the right animation to actually make the door open or close. In order for this variable replication to work (and for all clients and the server to see changes in the door’s open/closed state), this parameter must be “RepNotify” and, therefore, the door class must be set to “Replicates” so that the parameter changes actually get sent.
At this point, everything is fine. The server creates the buildings, and if I manually place a copy of the door into the level, I can click on the door to open and close it with either the server or any number of clients and these open/close state changes are synchronized on all clients.
A Step Further: Now, most people like having buildings with doors as opposed to buildings without doors. So, to make my building “doorful”, I open the building blueprint, go over to the Viewport, and then drag my door blueprint into my building blueprint. As expected, the door is added to the building as a “Child Actor Component”. Great! I compile and save my building blueprint, and now when I run, my buildings have doors.
Where Everything Goes Horribly Horribly Wrong: Now, however, when I run the level, the server spawns just one (I checked) copy of the building class – but it also spawns 2 copies of the door class. So now, both the client and the server have 2 copies of the door (4 total). Not only that, but when I click on the door on either the client or the server, the state is no longer replicated. The client does not see when the server opens a door, and the server does not see when the client opens a door.
I don’t think it is unreasonable to have Child Actor Components that need to use Replication or RepNotify for their attributes, I also don’t think it’s unreasonable for blueprints that contain Child Actor Components to also need Replication – so I don’t think that this is an “edge case” scenario by any stretch of the imagination.
Can anyone tell me why the server is creating 4 copies of Child Actor Components in multiplayer games?
What am I doing wrong here?