Replicate Textures from Host to Client

In many multiplayer games, such as CounterStrike, Overwatch, Team Fortress 2, etc, players have the ability to display a spray image that all players can see. This is basic replication. I am trying to achieve a similar effect for a multiplayer game, but I am running into a problem. For what I am trying to accomplish, the texture is not packaged and could be anything, as the texture data is generated from a Scene Capture Component and saved to a Texture Render Target 2D (TRT2D). This TRT2D is then used in a dynamic material instance. I am using UE4.13.1.

The issue occurs when a Host generates a spray and then a player - who was not in the session - joins the Host. If the Client is joining after the “spray” has been created, the TRT2D is blank for the spray. If the Client was already in the level, there is no issue of accomplishing this because the Host can send the Client the exact location of the spray and the Client can generate the same texture that the host is using in that location by saving whatever the Scene Capture Component is looking at into his own version of his spray.

I can accomplish sending Text from the Host to a new Client when he joins the session (Host sends a string to the server through a blueprint custom event that then sends the string to all Clients (also a BP custom event)), but when I try to send the TRT2D using the exact same method, the TRT2D is always Valid for the Host but is Invalid for the Client. I found a LogNetPackageMap:Warning that said that sending a TRT2D is not supported, so I made a temporary engine mod to ignore this and I was still unable to complete this task. I made an function that would continually check for the validity of the texture, but it would never become valid, thus it is my belief that the texture was never sent over properly to the Client.

Because of this, I decided to pursue a Web server idea which was how another dev accomplished this task: sharing pictures between clients at runtime ? - C++ Programming - Unreal Engine Forums.

I just feel like there has to be a better and more natural way to send over texture images to Clients and avoid a Web server implementation in this awesome Unreal Engine. Any advice is appreciated. :slight_smile:

Could you simply have the client search for all the spray objects on begin play and run the texture generation code on each of them using the same arguments you passed to it the first time? (Presumably by saving that data on, say, the gamestate for later reference)

1 Like

When is the Texture generate? Runtime?
Because if yes, why can’t you send the Client the Data to recreate it by using his own SceneCaptureComponent with the same settings?

Other than that I would have thought you could use the OnRep functionality to call the function for creating your texture once the variable replicated.

Sadonis, the problem is slightly more complicated for me. My sprays are dynamic and involve the scene, which can be changed by players and/or objects moving around, etc.

eXi, yes, the texture is generated at run time. The reason why I can’t simply send the new Client the Data is because my sprays are dynamic and involve the scene, which means things can change and would look different for the Client vs the Host as they are taken at different times. I would love to just simply send the exact texture over, but the raw data won’t work from what the link I posted says, and I have personally tried sending over the TRT2D with no success.

You could make the texture be a property of the PlayerState, and thus get replicated to all players, even if they join later.
(That of course means you’ll have to set up replicating textures, which can be pretty large data blobs …)

Hello,

You can use this plugin for multiplayer texture replication.

Unreal Engine

Replicated Texture - UE Marketplace

Built-in Multiplayer Replicated Texture without external network system ( HTTP, website … )

Texture replication is available for Windows, Android, iOS, Oculus, Linux.

Bandwidth usage is optimized, the texture data sent via network are compressed using external image compression library and then uncompressed when received.