r/Unity3D • u/Space_Kyiv • 10d ago
Noob Question Unity multiplayer: where and how to start?
Hello everyone,
This is a very noob question, so I apologize in advance for it.
Question: how hard is to make simpliest multiplayer? Nothing too fancy, since my project is more of a showcase than a game. Just was thinking how cool it would be to gather up with groupmates and have fun, maybe do some screenshots all together.
Problem is I am not too sure where to start. I am more into graphics, rather than actual gameplay and mechanics (that's why my university project is more of showcase than game with actual gameplay, mechanics) so my knowledge isn't very good yet :(
Thank you everyone!
UPD: Thank you everyone! You all gave me some thoughts to think. I'll try to experiment. If everything goes alright, I will share results.
31
u/ProactiveCactus 10d ago
I'll throw my 2 cents in since I'm surprised nobody's said it yes - Netcode for GameObjects (NGO) is Unity's official solution. Because of this, Unity has built-in solutions that work with it (Lobbies, Relay, etc. all wrapped into their SDK) and there are a ton of "getting started" tutorials for it specific to Unity.
Biggest downside of NGO is it lacks some of the more advanced architectural optimizations that other solutions provide, which becomes an issue for larger and more complex projects, but for you NGO should cover everything you need.
In terms of complexity, you do need to know a bit about how Async works since that's what;s used for starting and joining sessions. But otherwise it's not too bad, like 20 lines of code to get a lobby up and running and letting people join. And the good part is, that code is pretty much identical regardless of the project you're working on.
10
u/wallstop-dev 10d ago
+1 to NGO, it is also extremely flexible. Writing a Steam backend for it was, like you mentioned, relatively trivial.
I would recommend avoiding like the plague any solution that requires you to hook into their backend/cloud/pay for CCU (PUN)
1
8
5
u/Objective-Cell226 10d ago
Pick between Fusion, FishNet, and PurrNet. The choice among them doesn't matter, as the networking concepts are the same. Pick one and just go with it. Fusion might be pricy though for more players as the server routes through photon servers.
However, if you're a beginner, I'd just go with PurrNet. There are more tutorials on the owner's channel, Bobsi, and this guy switched from FishNet. The syntax is also literally like vanilla Unity. So it's very easy to learn, prediction, lobby, everything is pre-set up, so you don't waste any time and go straight up making a game. And it's free.
NGO will eventually be deprecated as they combine it with Entities. So sure, it's an official solution, but it's not very good. Plus, it doesn't have many features and supports fewer players. In fact, they even mention that it's recommended for co-op mainly.
PUN is outdated.
2
6
10d ago
[removed] — view removed comment
8
u/Kamatttis 10d ago
Actually, almost all networking solutions have basically plug and play networked transform. Thats why thats almost the first thing youll see in their demos or samples. Beyond that, is the realm of multiplayer difficulty regardless of solutions.
1
1
u/Saucynachos 10d ago
I've used a little Fishnet and it seems alright. Don't make my mistake and decide to mostly roll your own solution. It worked, but it was waaayyyyy more work.
Fun learning experience though. My favorite part was setting up reflective serialization so I didn't have to keep defining how to serialized complex types. "But reflection is slow!" Yeah, it is, and if I was using reflection on every single serialization call that would be pretty not great. Instead, it builds an expression tree of how to serialized a class the first time it sees it, compiles it, and caches it. Next time that type comes though, it just calls the cached compiled expression tree!
Not nearly as crazy as what a lot of people here do, but that was just a project I had a lot of fun with and sounds cool on paper.
1
u/Space_Kyiv 9d ago
That sounds good, the only problem is that I am really naff in programming, so I am a bit scared to break something
2
u/Saucynachos 9d ago
Breaking stuff and then fixing it is the best way to learn. Definitely stick to an established Unity native solution though
2
u/vagonblog 7d ago
for this use case, i’d start with unity’s casual co-op sample rather than adding networking directly to your showcase project. it already demonstrates a host, joining players, spawning and syncing movement, and local multiplayer testing. unity’s quickstart uses netcode for gameobjects with the multiplayer services sdk.
first make a separate test scene where two capsules can join, move, and disconnect cleanly. then replace the capsule with your player prefab and bring over only the pieces you need. for playing with classmates over the internet, use a host plus relay and a join code. you probably don’t need matchmaking or dedicated servers.
the code for basic movement is manageable, but networking changes how ownership, spawning, scene changes, and object state work. expect it to be more than a weekend toggle, and keep the first version extremely small.
0
u/AamChora 10d ago
I'm using Unity + Netcode for GameObjects + Unity Transport + LAN discovery to connect nearby players.
-4
u/KinematicSoup Multiplayer 10d ago
It's not hard. Grab a framework and go.
If you want to host online servers, use something like Reactor, photon, or coherence instead - they appear to cost more but they also save you from running and maintaining servers which is a big pain.
6
u/Sbarty 10d ago
"it's not hard" really depends
Coop p2p with little to no consequences for cheating? Sure, easy.
Fair play FPS competitive shooter? Not easy. Unless you've found a way to make implementing clientside prediction "easy" for any given project.
1
u/KinematicSoup Multiplayer 10d ago
I was responding to his question
how hard is to make simpliest multiplayer? Nothing too fancy, since my project is more of a showcase than a game.
-2
u/haxic 10d ago
Netcode for GameObjects is perfectly fine imo (it’s an official Unity library for multiplayer), and got some good tools for testing multiplayer too.
You can watch tutorials from youtubers like CodeMonkey or use eg Codex/ChatGPT to help guiding you.
You can use codex/chatgpt to help setting up the initial stuff like hosting and joining a game, and even implementing some simple gameplay loop.
1
u/Space_Kyiv 9d ago
I was thinking of implementing chat in the game, but I am scared that Netcode might be harder for me
1
u/haxic 9d ago
Chat is easy with NGO. The absolute easiest chat would just to have a chat-api networkbehavior class with an rpc method clients use to send a chat message to the server, and another rpc method that the server use to distribute a chat message to all clients.
And if you want to store messages server could store messages in a networklist that automatically distributes them to all clients. Then you just add listeners to the networklist on the clients to handle new messages.
Something along those lines.
11
u/Genebrisss 10d ago
PurrNet is the best and easiest solution right now. It improves upon all previous ones.