My latest endeavor is a game that can be played Single player or multiplayer (where you connect to a server hosting a persistent world). However, other then the method of play, the gameplay itself is all exactly the same. The best examples I can think of for this are Minecraft and Terraria, where there’s essentially no difference in playing solo by yourself, or logging into a dedicated server running the game.
My questions comes to determining what the best practice would be for developing this. Through some experimentation, I’ve determined that I can use Switch Has Authority, and everything seems to work as I need it to. I can run the dedicated server, and then from a “client”, if I choose multiplayer, then it connects to the server and doesn’t have authority (as expected). If I choose “single player”, and load the same level that that the server loads, then that stand alone game (running solo, not connected to the server) has authority.
While this seems to work, I want to see if there’s something I’m missing. The Single Player version has a bit of overhead to it, as it’s going to be going through a lot of Switches determining authority, whereas a normal Single Player game wouldn’t have that, but it’s pretty minor. However, that bit of overhead seems like it will prevent me from having to essentially create the exact same game twice.
I’d be curious to get some others thoughts on this, and see if there’s another solution that I’m completely missing, or if I am going about this the right way.
I think that first “Single Player” was supposed to say “Multiplayer” … if not, then I am very confused.
The easiest solution is probably to not distinguish between Single Player and Multiplayer. In either case, create a dedicated server and connect to it and all the code will work the same.
This does make me wonder though … if you have a Singleplayer game without a dedicated server and you execute RPCs and replication, will it still work? It would be a little funky as your client would effectively just be talking to itself but it would allow you to code for multiplayer and still have it work for singleplayer (without a server).
Chumble. I likely didn’t do a great job explaining this. I did mean that the Single Player would have additional overhead, which is described better by your last comment, which is what I’m trying to figure out. Essentially it causes a single player version of the game to talk to itself for RPAs, replication, etc. It “seems” to work, but I’ve only done a couple of simple tests.
Hey I have been asking the same question. What did you fine out? the switch thing seems like it would work, though it’s not very elegant. Did you come up with a better solution?