Context:
I am working on a game which will offer various ways of multiplaying, namely couch/splitscreen, LAN and online. My problem concerns the last two methods, which I am implementing using Netcode for GameObjects for LAN, and a combination of Netcode for GameObjects + Lobby + Relays for online.
Since both of these modes make use of the NetworkManager and UnityTransport components (albeit with slightly different settings), I am trying to have a unified implementation where the UnityTransport component’s Protocol property can be simply set programmatically based on what the player has selected.
In other words: I have a menu scene containing a NetworkManager component. Said NetworkManager component references a UnityTransport component, and this UnityTransport component has a property named Protocol which should be set to either the “Unity Transport” or the “Relay Unity Transport” protocols depending on whether we are going for a LAN or a Relay connection respectively.
Problem:
The Protocol property of the UnityTransport class seems to be defined as read-only, and only exposed for editing in the editor. The UnityTransport class seems to offer no methods to set the protocol programmatically, and there are not constructors which take a ProtocolType parameters…
![1]
Question:
How can one go about setting the protocol if not from the editor?
I could default even LAN games to go over a Relays in Unity Game Services, but this seems unnecessary. I have also considered storing prefabs with the different settings and then copying the components over, but perhaps one of you knows of a cleaner approach.
TLDR:
How set Protecol from UnityTransport in code? It be read-only!!1!
Thanks in advance!
Quick References:
Unity.Netcode.Transports.UTP.UnityTransport.Protocol
Unity.Netcode.Transports.UTP.UnityTransport.ProtocolType