During conversion of my single-player game, which highly relies on Add Static Mesh Component during gamplay, I found it very hard to replicate such added components. I even cannot replicate the fact that component is added, so the static mesh is never shown in clients.
I have took a deep dive into replication and spent over 10 hours to understend the topics. Actor where Add Static Mesh Component is called is definatelly replicating, also I am adding this component through Switch Has Authority so I am sure it happens on server.
I have already succeed in dynamic component creation replication with adding a custom ActorComponent during runtime, where I have marked the component as Component Replicates in it’s definition. **But unfortunatelly, StaticMeshComponent has Component Replicates off by default and additionally I cannot create a sub-class with haiving ComponentReplicates enabled by default as inheritance from StaticMeshComponent is not possible.
I have tried to address that situation by immediatelly calling Set Is Replicated to true instantly after creation, but also failed. Note: That approach was actually successful with a component being a child of PointLight! (the fact I have spawned PointLight component dynamically replicated to clients and all clients were able to see the light).
I was also trying to make this component addition without Has Authority and all clients see the mesh, but unfortuntelly those are independent copies and do not replicate.
I assume I can solve the situation by embedding static meshes before gemaplay (statically) and hide them until needed, but it would involve refactor of half the project.
So, the question is: How I can dynamically, during gameplay, add a Static Mesh Component in blueprint so that spawned mesh is replicated and the fact of spawning is replicated?
Browsing through answers on the Hub I see there is a workaround with embeddeing Static Mesh (child) Actor, not Component, but it will reuqire a lot of changes in the project. Also I do not need that simple mesh to be a “full actor”. Can it be done with component?