Let me preface this by saying I am pretty new to multiplayer in unreal, but…
I am making a mobile game and I want to host a P2P server. I have this working correctly already, my issue arises when I try to replicate one camera to the other. It is a puzzle game and I want to make a multiplayer mode where you and a friend try to see who can complete the puzzle the fastest. I want to show the listen-server player’s camera to the client player’s screen and vise versa.
Right now, I am using a scene capture component 2D (replicated) on the player camera, that is “setting” a render target (RT_ SecondCamera0), that is then setting a material instance (MI_SecondCamera0). There is a UI - image element that is getting set to that material instance. This works completely fine in a single player environment, taking the screen and displaying it to the UI image element. The issue arises when I try to replicate it.
My current iteration of attempts is as follows:
Whenever the host player clicks play game, there is a multi-cast event in the ‘game state’ that fires off, making both players “SetTextures” (also a multicast function) which:
If server:
Sets the capture component 2D’s render texture to RT_SecondCamera0
and
sets the CameraMaterial (a material instance variable inside the player) to MI_SecondCamera0
If client:
Sets the capture component 2D’s render texture to RT_SecondCamera1
and
sets the CameraMaterial to MI_SecondCamera1
I then, after these have been completed, back in the game state, if the player is the listen-server/host, fire off another multicast event in the game mode that gets both players, and sets their UI images to the other one’s material instance. (server to MI_SecondCamera1, client to MI_SecondCamer0)
I currently have 2 different UI image elements one for server, one for client, but I plan to have only one if I can get this figured out.
With this current setup, the server just shows it’s own material on one UI element and a blank black screen on the other. The client does not show either UI element at all. I have noticed that camera material returned from the client is null.
I suspect that issue is either replicating material, and/or I probably should not be trying to set the UI through the game mode since it only exists on the server, and it needs to be set on both. However, I went through the game mode so that I can get references to both players, which have references to their current camera materials, and their UI elements…
Thanks for any help, I can add pictures of the node setups if needed, however, I thought it might just cause more confusion. Let me know if you need any more information. Fixes to my current attempt or a better way to do it much appreciated.
Unreal 5.4