Two Player Network Question

I’m close to completing a project and wish to now add a two player network option.

A while back I watched several videos on networked games and did a little reading on it too. Everything I saw required the network manager to instantiate objects into the scene.

My project has all objects in scene at startup. What I really need is to pass a couple of integers back and forth so each side knows what the other has clicked on. Everything I’ve seen is way overkill for my needs and I don’t know exactly what options I have. I know of free and for pay solutions, but probably not aware of most available and have not investigated any one for suitability or compatibility with my requirements. I’m hoping to narrow the field and get some advise along the way.

I’m sorry to say, these two claims are mutually incompatible.

Not very helpful, I realize, but perhaps in terms of setting expectations, at least…

Joe’s right, to a point: you do have a good bit more work ahead of you to get your game working with multiplayer.

Ideally, this sort of thing is built into the whole framework of the game. Retrofitting it late in development often means rewriting huge portions of code, and sometimes discovering that your entire system falls apart when operating across a network.

It’s not super clear what you have in mind for your needs, though. If it’s not a real-time need, the changes might not be as sweeping as it would be for, say, a FPS or something.

Could you give a bit more detail as to what your gameplay is like currently?

Ok I knew I’d have some backtracking to do, but I didn’t expect a ‘you can’t there from here’!

My project is a 2D turn based game. All game objects are prebuilt in the scene and ‘watch’ an array to position, rotate, and set which sprite image to render. The entire game functions by changing values in the array. I have an AI opponent function that has four different strategies it can choose from. I was hoping to hook into this function for two player. Timing is not critical. This is why I said that what I’ve seen is way overkill for my needs. I don’t need a leaderboard, user profiles, or much of what is available in UNET. Just a minimal lobby to create a match, and a way to pass a few bytes of data back and forth.

So what are my options? There are many in the asset store. Some are extensions of UNET and others seem more hand rolled. I was hoping someone with networking experience, preferably familiar with solutions in the asset store, to tell me what to focus on and what to avoid. I don’t mind going down a path as long as I know it’s going to get me where I want to go.

You’re right, there ought to be something optimized for a simple case like this. I imagine it’d be fairly common. And you’re also right, now that I understand your game better, that the actual coding changes on your end should be fairly minimal.

I’m going to watch this thread and hope to learn something too. Maybe somebody who has walked this path before can provide some recommendations.

If nobody does, and you end up having to do your own digging… please post back and let us know what you find! (EDIT: And this really isn’t a “getting started” level question… you might have better luck in the Networking forum.)

In Theory:
Let’s just say, for the sake of discussion, that your game is Tic-Tac-Toe.

If I’m understanding correctly, your game currently has Human-vs-AI working correctly. Awesome. I assume you have something like a board state that indicates whose turn it is to move. If the player tries going on not-their-turn, the move will be ignored, right?

So currently either the board makes a request to the AI to make a move, or the AI is watching the board state and checking to see if it’s its turn to go. Either approach is fine, I’m sure, but let’s go with the AI watching strategy.

The approach I’d take is to use an instance of an AIPlayer that checks in every second or so to see if it can make a move, and does so when needed. Then it goes back to watching until it’s needed again. A human opponent would work pretty much the same way. An instance of a HumanPlayer would sit in the game and watch and wait for its turn. When needed, it then grabs the board state and passes it across the network to the human player. On their end, then, everything would look like how your turn just started. Repeat as needed.

In Practice:
It depends on what platform you’re targeting (iOS, Android, Xbox, Steam, a toaster), but it also doesn’t. Abstract everything out to a MultiPlayerInput class that has any needed platforms handled inside it. As far as the Board/Gamestate is concerned, it only cares that the MultiPlayerInput is doing its job. Inside that class, conditional statements will use the right API or networking code to send notifications and data, and process its return.

In My Experience:
I’ve only done one game, and I didn’t do it well. :stuck_out_tongue: Meaning, I didn’t take my own advice above and just used the API in with all my other code. Which is why I only ended up releasing on iOS… I didn’t feel like going back through and decoupling it to be able to implement multiple platform APIs.

I think it’s commonly agreed that prime[31]'s plugins are the best. They aren’t cheap, though. And they do, in fact, provide a lot more functionality than you need. However, as I have no experience writing my own networking and matchmaking solution, I can’t say how much more difficult it would be to write everything yourself. I will say that you should never undervalue the inherent cost of your time, though, and saving yourself 50 hours of development time is well worth the $175 or so, in my opinion.

That said, Unity’s built-in multiplayer may still be the best option for you. Again, I’ve never used it, so I can’t speak to how easy and effective it would be (especially since it seems focused on real-time, and you’re talking turn-based here), but it’s effectively free until you start getting some heavy traffic, so it could be worth looking into a bit further if dollar bills are in short supply at the moment.

In my dreams:
Unity would provide a built-in solution that would be a simple matter of checking a few boxes and filling out a few fields, assigning some properties and then BAM: multiplayer all configured. But until that happens, we’ll have to keep on with the options we have!

Please keep us informed on your progress! This is one area I have a lot of room to improve on, and a strong need to do so!

2 Likes

Thanks for the replies. I agree asking this question in the networking forum would be a better choice for advice, but @JoeStrout , @Kiwasi , @Ryiah , @Schneider21 , and other are always so helpful and eager to help out despite the barrage of dumb noob questions, that this has been my goto for advise.

I’m not a developer. I am only interested in learning Unity, and game design. Nothing I’ve completed so far has even been shown to another, not because it is not market worthy, but because I didn’t enter this endeavor with the purpose of selling games, monetizing games, or even distribution for free. This is a total learning experience for me and sadly what I’m now doing for entertainment. I don’t have an aversion to purchasing some assets, but I’m on a very limited income level and don’t really have the resources to buy my way into this.

That being said, I’m plowing ahead with using Unity’s networking, as it is free, documentation including sample projects and code snippets are readily available, and it satisfies my goal of learning Unity. I’ve browsed the docs last night and see it is based on UDP protocol, which I’ve had some experience many years ago. I also found there is a messaging system layer that I just might be able to use as a method of exchanging the data I need to move back and forth without the usual networking mumbo jumbo UNET requires.

I’m now stuck, I don’t want to finish the single player part of the game, because I’m worried that it will be wasted time, if I have to redo for networking. This is going against my ADHD urges to finish what I started. Without jumping in and doing something I don’t know how to discover what I can do or what I can get away with to accomplish what I need. It frustrates me to bog myself down in mid project, while learning networking, but there is little I can do about it now. My original post was a cry for a direction, and I don’t think I’ve learned anything new here as my first option was always UNET and that is where I’m heading. Still hoping for more guidance and alternatives. And of course I’ll re-ask in the network forum too.

I’ll post my problems, questions, and progress as I move forward. I hope that’s not too optimistic!

2 Likes

I brought this back from Davy Jones Locker in hopes that someone with UNET experience can help me out on this. I have read and reread the docs. I have gone through all of UNET text and video tutorials plus dozens of 3rd party tutorials. And have requested help on the networking forums. Frankly I have no idea why the networking forum exists. There is little to no help there and even the Unity moderators don’t respond. For all appearances it has been abandoned by Unity.

I was able to replicate the HUD buttons with my own and was able to create a network and spawn a game object for each player. Then I hit the wall. I can’t seem to share data (name and stats) pre-gameplay.

Unity need to step up and do a much better job on this whole mess.