#Is it possible to change transport via script?

15 messages · Page 1 of 1 (latest)

fathom aurora
#

Is it possible to change transport via script (during runtime) like if instead I wanted to do local singleplayer so use KCP transport instead of a transport like fizzyfacepunch that requires you to connect to steam?

steady fable
# fathom aurora Is it possible to change transport via script (during runtime) like if instead I...

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.

fathom aurora
steady fable
fathom aurora
#

so, this can be overridden?

steady fable
#

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 😄

fathom aurora
#

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.

fathom aurora
#

I guess my players are gonna tough it out and have to just play with an internet connection at all times.

steady fable
# fathom aurora And I also tried the solution 2 and when One gets enabled, then disabled and the...

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.

  1. Server needs to be completely stoped, no mirror script is running.

  2. 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

fathom aurora
steady fable
#

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

fathom aurora
#

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)