#Is it possible to change transport via script?
15 messages · Page 1 of 1 (latest)
Yes it is possible. You will need to write your custom code for that off course. Stop the server. Wait until it stops, then change network transport layer via code. Start server again.
You will still need default transport layer on game object, as I think mirror requires it to be there, but you can easily disable it when u don't need it anymore.
Another aproach would be have two network managers, one with one transport layer, and other with another and just turn off server (host or what ever), disable one network manager, enable second network manager and start hosting. I would say this is easier, tho less pretty in editor.
Ok, the second would work for me, easy fix. Thanks, however I kinda hopped you would be able to just access the transport variable, however it is a protected variable in the source code and plus, that would require me to edit the source code and change the variable to anything else but a private protected transport variable, and would likely break mirror.
Yes, but you can overwrite any function that uses it . For example :
so, this can be overridden?
techincly no 😄 you would need to overwrite all overwritable logic and add your new parameter 😄
yea on second though the second variant is just way easier than editing a lot of code 😄
The problem that prompted me to ask this question was that I want my players to be able to play singleplayer and not have to connect to a steam server, so they would use a "singleplayer" network manager however there can't be two network managers at the same time so I would instantiate the one I needed with the right transport, however if you try and load a scene and destroy the old network manager, then lets say you now want to play multiplayer, we instantiate the "multiplayer" network manager however then these weird errors appear saying that a network manager already exists even though the last one was erased from existence.
And I also tried the solution 2 and when One gets enabled, then disabled and then the next get enabled, It thinks there are 2 in the scene when the other is disabled
I guess my players are gonna tough it out and have to just play with an internet connection at all times.
Well several notices. You can inniate prefabs as game objects. And destroy and despawn them.
Or you can make them singleton and just disable and enable them.
There is Core element to this tho.
-
Server needs to be completely stoped, no mirror script is running.
-
If singleton is used it is very important to disable before enabling, otherwise enabled one will destroy it self on awake.
Another thing that is quite interesting, If I remember correctly, before there were talk about how to have multiple transport layers at the time. Like if one fails and other replaces it. And also to run multiple layers at the same time, for example that webgl players could join PC players.
So it is actually possible to do that, tho it is not easy task
#🤝help-archive message
ah, so if the fizzyfacepunch steam transport fails (EX: Player has no internet) and the kcp transport is the next available component attached to the game manager, will it automatically use that one?
if you use multiplex or what ever that is called, yes. But you can use it as your core logic to switch transports. I know it was made, but I checked it ages ago, I am not sure how much it was changed and if it still usable after mirror moved a lot of logic to transport and removed alot of that logic from mirror network manager it self
when one of the network manager are started, then deleted, then a new one is instantiated from a prefab, then the host is started, it claims that the host has already been started? (Yes, I'm calling stop host and everything)