#archived-networking
1 messages ยท Page 50 of 1
The jitter also seems to happen with just non script driven parented unity camera.
then its just shit interpolation code
The car is non-kinematic?
with interpolation = true?
We are talking dumb clients - so I expect it to be isKinematic == true on all dumb clients
I'm going to try and get one of the devs on the project to hop on here.
when kinematic you either have to move with MovePosition() every Fixed, and enable Interpolation on the rb...
Or you need to store your own lerp points in Fixed, and interpolate manually in Update
Ping me in here if you get them
I saw that in many authoritative setup you have some kind of input manager that sends inputs to the server to remotely controls players, i was wondering isn't it easier to have this input manager being a local object and control your player as you would do in local too ? Since you have to predict by already doing that why just not send positions and reconcile when its off ?
That is prediction. Prediction is applying the same inputs and simulation code locally every tick that is applied on the server.
The server broadcasts its state results for that tick, and the owner checks its history to see if it got the same results. If so... all is fine. If they disagree, it has to set itself to that server indicated state (along with anything else you may want to rewind and include in the resim), and then reapply the inputs again for each tick between that and current.
You don't send positions typically from the client, because the server doesn't care for most networking setups.
It is on the client with server authority to get itself back into agreement with the server.
But then how do you check for wrong posisionning if you dont send the position ?
The client checks, not the server
The server does not care what the client thinks
The client is just guessing at how the future will play out on the server with the inputs it has given.
But if something on the server blocks you, or a weapon pushes you or your packets get lost and the server has to guess your inputs.... you will now have the wrong view of reality as the player, and you will know about it when the server gets its tick results back to you.
You can send your client state, but that doesn't gain you much, unless you are going to have the SERVER correct to match the client...
But that what was the point of server auth?
But isnt it wrong to trust the client for correcting it self back ? How would the server know that the client did correct it self ?
No, that is what you want... there is no trust there
Is it like if the client doesnt want to correct it self then he won't have the right sim ?
The client can go off into space for all the server cares.... its not going to see things that way.
If the server says you are at 2, 3, 3 .... that is where everyone will see you. If you choose to say you are at 200, 40000, 30000.... that is your problem
Ahhhhh this is actually funny ๐
The server doesn't correct....
the server is god
once it sims... that is it. That is the word of god.
Yeah its like "go on cheat, you will randomly die" ๐
Your player will find out its out of sync a moment later, and needs to get back into sync, or else the player will be seeing things all wrong.
exactly, you will just be seeing a lie as the player - that is no benefit
This is pretty cool so position is only broadcasted from the server
You still have to
that is the typical pattern for non-deterministic games
Clients -> inputs -> Server -> results -> all
This is not deterministic ?
Deterministic follows the pattern of only sharing inputs.
That is the point of determinism, the results will all agree, if everyone gets the same inputs.
Obviously that is much harder to do that just sharing inputs. It is very hard in fact.
This would be a blast for traffic
yeah, it allows massive simulations with very little traffic
Thats where the physics problems comes from
as well as how to predict and correct
Different time step different CPUs
you have to constantly be guessing other players inputs, and then resim as the real values arrive.
time step isn't the issue, this is all fixed step
If the buffers start to grow or shrink too much you have ways to deal with that. The issue is that the player no longer has her own view of the world that is different from everyone elses.
standard networking the player usually lives in the future, and the server allows for that and favors the shooter.
deterministic networking you extrapolate the networked world so that you are in the present, but the present isn't known yet - so it does a lot of constant guessing and reguessing while it waits for inputs.
If the physic is the same for everyone you can extrapolate ?
by definition
deterministic means exactly the same results for exactly the same inputs
The guesses are wrong for the extrapolation
Hmm ok
but they aren't "real", they are cosmetic
so the player has a close to real as possible guess at things at all times
Feels wanky
The player doesn't see 100% reality
Because she sees the future at all times
its not ideal for all game types
fast counterstrike FPS games are likely to never be fully determinstic, because players can be too erratic for the extrapolation
but for like a vehicle sim, its really good usually
fholm had a sample of Quantum working with an FPS, and the extrapolation rubberbanding was pretty minimal though
I seen that in tf2 you can change your interp value to basically backstab peoples where they were but in the present
You are extrapolating user inputs, so they tend to extrapolate pretty well... if you were holding down the w key last tick, its a safe assumption that you still are.
Is it ?
Safer to assume so than not
A clif begs to differ ๐
Anyway, I think that answers your original question
Yeah thanks for all the info i was actually wrong on something i didnt even touched yet heh
I was just thinking of something if the client moves himself around the battefield, then he can spot other players
You can't just let the client unsupervised
Let say he is on one end of a tunnel and then teleporting on the other side he will see the other players before they do
If you don't control what it sees on the server side yeah
Ohhhhh
giving players other player info that it doesn't need is always a security risk
Why are you worried about any of this btw?
Security is NOT something anyone making their first games should be thinking about, its futile at best.
Thats why players dissapear when you lag in csgo
Im just trying to figure things out..
Could be, don't know their code base all that well
I dont either just guessing but when you peak with high ping there is a chance players will dissapear for a few
https://youtu.be/6EwaW2iz4iA
Regardez "How It Works: Lag compensation and Interp in CS:GO" sur YouTube
0:00 Lag compensation 2:00 Interpolation
That may just be that it won't extrapolate past a certain point and is making it clear to you that you are lagged out
yeah, familiar with how CS deals with latency and buffers
just not the details of how it deals with timeouts and such, that is all pretty unimportant
Those parts are always evolving as people tweak settings and such
CS was the standard for basic FPS shooters for quite a while. Bolt follows its spec pretty much exactly.
How would you control what the player see ?
You would still impose the camera a culling over the network ?
You just don't send updates for entities to players the server feels should not be able to see them
based on distance, or some complex line of sight checks... whatever you feel like doing
But you shouldn't really even be thinking about this stuff yet. Not even Apex or Fortnite think about that stuff
They just have basic distance zone checks as far as I know, and that isn't anti cheat... that is just to keep packets under control
Focus on that logic, how to not waste data.
Or really, just finish something, then evaluate it.
True thanks for that
never trust the client
and never trust a fart.
thank you for attending my ted talk
Hey so does anyone know when the newest version of unity will have built-in multiplayer support? Or otherwise what would it look like to try and make a multiplayer game in unity right now?
@spice void What do you mean with built-in multiplayer support?
@stray scroll as in when I go to add the multiplayer script to my project files, Visual Studio Code will understand what I am trying to do and not try to tell me that there are errors that are not really there.
Not sure what multiplayer script you're referring to? But you can check out the new multiplayer stuff exists on https://github.com/Unity-Technologies/multiplayer . (I don't get any errors when using it). But it isn't just plug n' play, you have to set it up and use some of their tools to generate scripts etc. I would image you'll have to download the package later via the Package manager.
If you're no fan of ECS, I would recommend go look at Mirror or Photon.
@stray scroll I have been recommended Mirror and Photon as well. I was just hoping to find out what version of Unity would be best for making a multiplayer game using any of these tools?
What unity version is compatible with Mirror or Photon?
2017+ for Pun2
2018+ for Mirror
Any for unet and pun1
I believe
Generally I would try to stick with LTS versions, unless you have good reason not to.
Should i make a new project with UNet or switch to photon
UNet is deprecated IIRC.
Yeah, i guess
But you can still use it
I guess ill learn photon ๐
So do i wanna use PUN or photon real-time?
I guess pun
Just saw it was a plan
Pun is a bit different from UNet
What do you want from your project?
Do you want an easy networking solution, or do you want a high-performance solution? @rich flame
You really have to define your project first
Probably a P2P fairly easy system, ive already familiarised myself with unet
before deciding how it will host
Probably a first person multiplayer sandbox
With p2p support as i have shonky internet and no real income
Competitive at all? Or super friendly coop?
Coop with some moments of competition
P2P can still be client-server
Yeah
Honestly you won't be able to make this choice with the limited experience you have now
I know
you need to go make a demo in a few of the platforms
Many games use a client-server model where the server can be/is locally hosted as a P2P model
before even asking this question
Minecraft is one of the games that does this
That doesn't matter though, I have a game I made when I started too... networking laughs at single player games
UNet is deprecated. It's never a good idea to use something that is deprecated
You have to go make some basic demo games first
or this conversation won't really have much meaning
I guess
Have you made a PUN2 or Mirror garbage demo game?
Bolt, Forge, PUN2, Mirror are the HLAPIs you mostly have to choose from - I would spend a day trying to make a tutorial in each of those
Ok, thanks for the help
a day for each btw... you won't get much done - but you need to get your hands dirty in them a bit to start getting them
Okie
how would you display pun2 ping latency on scene canvas? figured it out
Hey! I have a question. If I want to use a local p2p system (just for testing) with 1 host and multiple clients, and want to simulate physics what would be a good option? Right now I was thinking of 2 ways.
-
Have a separate physics scene on the host client which will tick at rate X, thus disabling autoSimulation on the host client and manually calling it for scene's and then have full control over the speed at which the server ticks. (Which is probably heavier though since you now have to tick X times more every second)
-
Have the host client calculate everything in
FixedUpdate, thus having less control over the tick speed since physics still have to look good for the host client, thus update quite often. However allowing to do everything in the same scene and not having to tick more then it already does.
Any idea if these are regular approaches or just really bad ideas, or can be improved on a specific point? ๐
I just realize option 2 might be very bad, because you can't really hide simulating multiple inputs from users, imagine a player has send 5 input states and you are calculating that inside 1 FixedUpdate, then you'll have clients bouncing all over the place for the host ๐ค
When you start talking about a host, that isn't what I would consider P2P
P2P generally is a terrible term for networking anyway, because it rarely means what it sounds like
If you are talking about a proper host, that is a server - it just happens to be run by one of the players
unless you want relay, like PUN2
If you are talking about a host, as being an actual proper server then you generally have that server act as the final word of god for the simulation state results
Then let's call it local clients connected to each other with 1 of them having the server inside the same application as the game ๐
Thus the server being hosted on a client
That is server client, and the server having a client. UNet called that "Host"
But that term isn't universally accepted, but that is another discussion
But you are describing Server client
Multiple clients connected on a local network to a host
In my case for simply testing it's lan only.
Nothing more than that for now, just to keep it simple.
I would not test for a net architecture you don't intend to actually use
because making something work on lan and the internet are two different paths
You will make choices for LAN that will break on the internet, so if you plan to ultimately make this a net game, plan for that now.
It matters because on lan, you can just have the server simulate and make all clients dumb with no prediction and call it acceptable
On the internet you have loss, lag and jitter - so you have to implement real buffers, lag compensation, and prediction
If you build it "simple" without that - you are going to end up throwing out all of our work and will have to start over.
are you on PC or Mac?
PC
get clumsy
to simulate the real internet on lan
Anyway, so to the actual question, let me reread
You can have your primary physics sim run on the basic fixedUpdate without turning off autosimulate, won't matter that much.
But if you plan to get creative with adjusting your buffer sizes on the fly, you can do the overwatch thing and have your clients tweak their sim rates to make the server happy with its buffer
Not sure in your question why you think that calling Simulate() yourself would result in more CPU work?
You are trying to simulate each player separately? Don't do that.
For networking you buffer everything
Messaging <-> Input and State Buffers <-> Simulation
the server holds a small buffer that collects each players inputs, and it consumes them each tick
No? What I was trying to say with I assume you're talking about option 1 is the following.
The hosts runs the server sim in a different scene, when you're ticking that at let's say 30 ticks a second that will be on top of whatever the host their game is running.
Let's say the host their game runs 50 physics steps each second then on top of that their will be 30 physics steps right?
If you want to totally isolate your simulation for the server you can do that sure
But it would still be done normally on the same tick rate that clients sim at
Depends whether or not you turn of autoSimulation for physics.
You need all of your sims to run at the same rate
Otherwise you break the ability to predict
You can send every 2nd or 3rd sim tick as a net tick
like you can sim at 60fps and send at 20fps
But the simulation (physics) ticks should all match if you want to do any prediction (you do)
To answer your question... there is only one sim rate... and everyone uses that
Anything else will lead to chaos, madness and failure
turning off autosimulate is useful for if you want to tweak with the fixedDeltaTime a bit to subtly tweak buffer sizes, or to resim stuff
But you do not want to be mixing your simulation rates
So if I understand you correctly, assuming we are the host. If I want a lower tick rate for the server I'm better of just sending every 3rd sim tick (assuming we have 60 sim ticks a second) a message to clients then creating some kind of separate scene which has it own sim rate?
best to name your ticks in conversation here to avoid any murkiness
sim tick and net tick
sim tick is the rate at which the server and all clients do sim calcs... taking inputs and producing new states.
net tick is just the rate at which you send those.
if you send every 3rd, you will need to bundle the last three user inputs, because the server will need all three inputs the client applied to its prediction sim, to apply to 3 ticks of the server sim.... in order for them to agree
Keep in mind, lowering your net tick increases latency in a couple ways
For anything competitive you generally send every sim input and state result as soon as possible
You don't need a separate scene for simulation on the host, unless you are really going for a true Server/Client separation
So basically there isn't a single 'tick', but you have a sim tick rate and a net tick rate? But are those the same for both client and server? So if the sim tick rate for the client is 60 does the server also have that rate?
It is pretty common for the host scene to just be the authority scene - but that does give the host player a MASSIVE advantage
I guess we should back up... are you planning to do client prediction?
are you planning to do client prediction?
Yes, that was my goal to learn ๐
Then clients and servers are both simulating - at the same rate
the clients only simulate themselves
Unless you are extrapolating players, then you have to sim them all with input guesses and such
But since you say you are learning, I assume just basic interpolated states is what you are doing right now
Player presses keys... each tick the client collects those inputs... applies them locally to its own self sim.... sends those results with a tick id number to the server. It consumes that tick when it is time and simulates with it (along with inputs from other players) and server spits out a state results. Owner gets back a state result and tick id. Owner checks that state against what it got for that tick id. If owner disagrees, owner sets its state to what the server said, and reapplies inputs and resims from that tick of disagreement back to the current tick.
So if I understand you correctly. The player holds let's say the W key. We apply that in fixed update, and after Unity is done with it's own sim we grab those results and send it along with the current sim tick to the server. The server puts it in some buffer, and then when the server their next sim tick occurs they send back the results with the sim tick from the client. If the client sees that the stored result on the client is different from what the server send them then the client recalculate's all inputs from the given tick to the current tick?
Generally speaking you don't send the client results to the server, but you can.
Server Auth = Server decides what the result was... client doesn't
The client is just simulating its guess of what the server will also say
So you get immediate feedback
If the server however says "nope, you bumped into this other player" - you will hear back from it with a different result than you got
And it is on the client to resim and get itself back into agreement
Basically what you were saying, but there is no point wasting data sending your state to the server
So instead of the current state of the player, I only send the inputs to the server?
But how do people store input from a client from Update -> FixedUpdate, since Update can occur more or less than FixedUpdate. ๐ค
And you don't want to get input inside FixedUpdate since then you're going to miss things like GetButtonDown.
Would a buffer work in which we keep the latest input for that?
So if I've 5 frames with input and then a FixedUpdate I keep the last result in case another FixedUpdate occurs before Update, and if Update occurs I just simply remove that last value and replace it with this one, and from that point keep buffering.
the standard unity way, you capture the inputs every Update() and hold that
All that matters is whatever you do, you are applying the same inputs to your client sim tick as you do to your server sim tick
how you collect those inputs, totally up to you.
How you deal with getting inputs into PhysX in FixedUpdate is the exact same concept
only you are storing and numbering those Fixed Updates inputs and results
The main benefit of manually simulating there, is you can get an actual PostSimulate() timing
since Unity has no PostPhysX timing, which is a pain in the ass.
I've another question, if people use relay servers for their game. How on earth do they make authoritive servers, since like you said sometime ago. If you use the clients with 1 host concept you'll get massive amounts of delay. Client -> Relay -> Host -> Relay -> Client.
you don't
relay isn't used for competitive stuff, unless you make use of server plugins
You typically only use the Master in that environment for lazy stuff like marking the end of a match or something
You would want to give clients a lot of authority in relay environments
Ah, alright.
That being said, it can be done. I have my demo scene I test for my asset connecting over a mobile hotspot here in Mexico, to a relay in Europe and back twice.
But with a lot of latency?
fair amount yeah
But let's say you're using relay servers. How would you go about for example picking up items, or in general authority? What if 2 clients do it at the same time and send each other packets that they picked it up.
You have can either make it wait a split second for confirmation, or you predict and then undo the action if it fails
That is mexico wifi to EU relay servers... so the health bars on that target are two trips to europe and back
I really hate that a part of clients just can't connect to each other. Makes it so much more complicated :c
They can with NAT punch if you want to deal with that
But clients cross connecting is its own set of headaches
fine for two players, but you generally always want all to one
Still NAT punch isn't a guarantee that it will work.
Relay is still a server client, its just a dumb server
Btw, you said earlier on that if using LAN you don't need client side prediction. But clients can still lag on LAN, like a laptop connected to wifi right?
lag yeah, but you won't be dealing with a lot of jitter and such - depends what you consider acceptable
The main thing is to not spend a month writing code and testing it on Lan, and THEN finding out how it really runs on the internet.
Thanks a lot for answering my questions btw! Really appreciated ๐
np
Hello ive made a very simple script that works as a flashlight. The problem is when one player turns her flashlight on/off the other player can't see it
Iam using photon 2, i guess my problem is that i don't know how to send it to ther server rather than it only being client-sided
Iam really new to this. I tried following a guide, and read some documentation but i can't really understand this. Iam trying to syncronise whenever a player toggle her flashlight across the server so other people can see it.
@maiden sundial Post the whole script
can check through this thread as starters https://forum.unity.com/threads/onphotonserializeview-not-working-at-all.322871/
Question, if I want a player movement system with client side prediction and thus the server being authoritative. Would the only way for this being having a deterministic system for this. So sending the inputs from the client to the server and trying to get the exact same result on both the machine's?
Calculate for client send to server
Server then sends you to a position, which may or may not be exactly where you already calculated
If it is, then you dont teleport to that position, but instead continue
If there is a disagreement, server always wins and you snap to that position
I understand, but the way of telling the server where the client predicts it's going to is what I'm trying to figure out.
Right now the only way I can see this work kind of reliable is by sending input to the server as @jade glacier said before. However this will require determinism in the whole movement system, and I'm looking if there are any other options before I just straight up dive into this one ๐
If you are going to try to bake some forgiveness into the server, you can do that.
its not unheard of for clients to send their states, and have the server make a ballpark check of if those states aren't too unrealistic, and if so accept them @void burrow
I typically bake quantization into my owners results. By that I mean I compress states before sending in a way that is lossy... and I will decompress those on the owner and correct the state results to match that. That ensures that the server and the owner are more deterministically in agreement.
How do you referance an gameobject from the server? Normaly i would just use the gameobject, but since its a networked gameobject, does it need the netid or a network id of some sort?
Unet?
For Unet/Mirror I think the Commands and RPCs automatically know to use the netid.
You can pass the GameObject as a parameter as far as I know, but yeah - you would if rolling your own grab the NetworkIdentity.netId
Unet yes, so i can just pass the local gameobject as a referance? thats pretty nice
since commands are called on the player object that is the host, can you call methods on that player object too?
you mean RPCs?
the RPCs and Commands turn it back into a gameobject reference on the other end
behind the scenes commands/rpcs get the netId of the gameobject, and send that as packedbytes - and on the other end look up the scene GameObject with that netid.
I believe at least. I never touch Commands/RPCs but that is what I recall.
I mean calling specific methods on the host gameobject from a remote client (not host). I could probabl make an method that does it, but im just wondering if Unity got something already built in. Yeah i would would guess thats how it works too.
You will have to be more specific in what you mean by calling methods
because that is yes or no, depending if you are talking about commands and rpcs or not
say host gameobject has a script with a method called "logme", how do i call this from an remote client that is not a host?
yeah ive read the docs a little and watched 2h videos about it a while ago
You should do some tutorials. You need to be familair with the usage of Syncvars, Command and RPCs in order to use the HLAPI
yeah ill do that
I mean, for fps, basic movement can be made deterministic so easily its laughable
You should see the simple calculations that something like csgo makes for movement
And people have gone so far to become โmovement expertsโ in that game
Mirror 4 is live on the Asset Store
Download: https://assetstore.unity.com/packages/tools/network/mirror-129321
ChangeLog: https://mirror-networking.com/docs/General/ChangeLog.html
when in the Unity editor, do the first person arms show with local client? I'm having a bit of an issue with it, and I'd just like for it to look like a normal proxy player
Does anybody have a resolution for something like this?
That sounds like a very specific question to your own code, so nearly impossible to say @exotic valve
Am I the only one having issues with PUN not finding matches recently?
the editor often connects to a different region
while deving, hard code a region into your pun settings... like region us or eu @weak plinth
Ah that did the trick. Thanks ๐
np
Ugh - this network interpolation is killing me...
Has someone managed to get the famous source interpolation to work using PUN?
I even tried this script as a replacement for my current interpolation
http://www.gamieon.com/devblog/post/11/a-script-for-syncing-transforms-using-photon-networking
But the movement won't smooth on the client side
For starters, CS style networking is very reliant on server auth and player inputs.... so not sure how you are going about that with PUN
https://assetstore.unity.com/packages/tools/network/simple-network-sync-134256 For this, it replicates the transform from the authority to others on a regular tick, which is a subdivision of the fixedUpdate... so it samples and sends on a fixed timing, and all clients consume those from their buffer on that same fixed timing.... that gives you a meaningful lerp value for your interpolation.
Interesting. RPC's aren't managed by this?
that gamieon script seems to be relying on OnPhotonSerializeView or whatever its called, and that is definitely not a fixed based timing.
So you are generating your state updates at a totally arbitrary interval, which means trying to interpolate them correctly is nearly impossible, unless you serialize in a time stamp, and pull from the buffer at the same rate the owner sampled it....
Which do DO NOT recomend
that is baking in all kinds of frame dependencies and insanity
I deal with it (and am talking with Tobi about incorporating it into PUN2 itself) by adding a networking update manager singleton, and all of my networking fires based on its timings. This makes it behave in a more Bolt-like way than the adhoc messaging that happens by default.
So this.. fix... might end up in the PUN2 package?
Its not really a fix, its just a whole alternate to the PhotonSerializeView way of doing things. I have a whole set of components that are drag and drop that use it, so they all defer their timings and such based around that master timing singleton. Not everyone would want to get their heads around that complexity of that, and may be fine with just the adhoc messages.
But they do cause serious problems with things like micro-jitter and any kind of determinism or keeping things generally in sync and in agreement.
All of the HLAPI suffer from this
UNet, Forge, Mirror also have no built in handling for fixed tick or simulation based timings.
So the 13.4โฌ i almost threw at this asset can be for naught if it is integrated into PUN ๐
even though you would benefit from it
And they all suffer on this front for it
I have no idea on the timeframe for if/when it will become part of PUN2
Well 13โฌ is most likely worth it anyway. I'm gonna try it out
The main thing in your case is to dig around what is going on with the NetMaster and the NetObjects as far as the interface callbacks
Its all about breaking down the fixed steps into a bunch of deferred timings, so things are very molecular in the order in which they occur each tick
The main takeaway, is that it ALL happens on a fixed tick... Update() is ONLY for interpolation between those states, and is entirely cosmetic.
All of the action happens around the FixedUpdate/Simulation
So i threw the SimpleSyncTransform to my character prefab and the interpolation seems to be working way better, but there are some serious jerkiness.
I'm trying to integrate this into the MoreMountains TopDown / CorgiEngine
So I rely on their input
Be sure to find all places that controller does anything and only have it happen if IsMine
Usually what you are describing is a controller not designed for networking not knowing it should be hands off on dumb clients
IF they don't advertise their product as being Photon friendly, then they haven't done any of that work for you
It's the network character that is "almost" rubberbanding
I might have some old interpolation code left somewhere
so the Observed Component of PhotonView is supposed to be empty right?
yeah, may want to start from scratch if you are pretty deep in making a bunch of test code
it should just consist of... move the object on the authority... let the synctransform replicate that out. and that is it.
The only issue being if that controller code doesn't know to be hands off if its not the authority
Nope, the network entity is still twitching aound
have you modified their controller code?
to not do what it wants to do if not the authority?
An easy test just to see if things are working, is remove that controller entirely... build out the project... and move the object in the editor by hand dragging it around the scene
Ah will do
That should replicate very smoothly on the build client
unless your internet connection to PUN is just awful, but that isnt likely the case
Other test is just open up the PUN example and see how smooth that is
There seems to be some fluctuation in my ping at the moment
but will try the Demo_Scene
The sample scene uses my own controller so if that is jerky, you are dealing with some really nasty internet noise.
if its smooth, then its just that controller you are trying to use misbehaving most likely.
keep in mind too, that the editor is notoriously crap, run two builds to see a more realistic view of things
I think my issues were related to the Sen Every X in NetMaster
I forgot to add that singleton so it spawned and sent every 1 instead of 3 in the demo
needed to send more or less often?
its default is every tick, which can be a bit much for photon relays if you have a high tick rate
I increased to 3 and it seems better, atleast when moving the characters manually within the editor
the lower your net rate though, the more induced latency you will introduce, so its a balance with networking
is that related to the PhotonNetwork.SendRate and SerialiationRate? Should I touch those?
nope, this totally circumvents all of that
As a reference, this is me connecting from mexico over my wife's tethered mobile phone to Photon EU relay servers... so typically it should be pretty smooth even through that.
Where are you connecting from and over what?
24/1 ADSL from sweden to amsterdam
DSL can be barfy here in the US, not sure about there
I do have some issues as my ping to google jumps from 35ms to 150
Was the demo scene smooth?
but increasing the send every X from 1 to 3 helped alot
sounds like you were just pushing too high a tick rate there yeah
if you run default physics timing, that is 50 ticks a second
does a send every 2 work?
that makes for a 25 per second (depending on your settings).. which is in a reasonable range for a net rate
The big thing with networking is to try to do everything on the fixed, or on a fixed timing of your own.
the problem with trying to network things (like 3rd party controllers) that aren't designed for networking is they just do everything in Update, and have no concept of simulation
and that is hellish to network
Interesting, I would expect you to be able to get a higher tick rate with your proximity
But your connect be what it be
You can also change the physics rate, since fixed is tied to that
Does my example scene also start to have issues when you change it to every 2 ?
Indeed it does
that sounds like the upper limit of a viable net rate then for your connect to the servers
So that out of the way, is the interpolating looking good now?
Yeps ๐
So hopefully the code if you poke around it will make sense
you can use the plugin as is of course, but sounded like you more wanted to know how to do this stuff
so you can poke around my code to see how I went about it
It''s Time.fixedDeltaTime thats tied to the physics (and net) simulation?
yeah
its unity's built in fixed timing that most everything uses
you can make your own, but this is an asset, so I had to use that to ensure it plays nice with PhysX
Generally, best to not fight Unity in how it wants to do things
My fixed timestep is (default?) 0.02 or 50 ticks per second
Righto - will poke you should I run into more issues ๐
Hi! Anyone knows if there are any limitations to using Steam their relay servers? (Except the obvious that you are bound to their service) ๐
For example pricing, if there is any? Because I couldn't find anything about it ๐ฆ
@weak plinth btw, there are some hidden constants in NetObjectLite.cs that you can futz with. I future versions I have exposed them in a ScriptableObject settings - but for the first release I locked it at a pretty typical setting.
public const int TARG_BUFF_CNT = 2;
public const int MAX_BUFF_CNT = 3;
public const int TICKS_BEFORE_SHRINK_BUFFER = 8;
public const int TICKS_BEFORE_GROW_BUFFER = 4;```
At really high tick rates, you may want to push up those buffer resize trigger values
@jade glacier Good to know ๐
hey i am making a top-down tank game unsing unet
and i have just inplemented shooting but it is extremely laggy and synced very badly. I have tried adjusting almost every value of the network transform component. I can get rid of some of the jagged motion with interpolation but I can not fix the problem that the bullet just shoots out "too late" while moving. btw server on the left client on the right.
can anybody help me ? please
PS: its my first multiplayer attempt
i have seen this idea online. i can see how it would work but i do not know how to realize it in code
If you are trying to make your projectiles into networked objects that's going to hurt @fading apex
Projectiles and hitscans are usually treated as events, not as objects. Since they are in most cases completely deterministic.
So how would one do that in a peer-to-peer model? I'm trying RPC's now but it does not seem to work
.. well it DOES work but not synchronized
you mean shooting?
If you send your transform info at the same time as you send the fire event, and apply them at the same time on clients, then it will appear to originate from the player at the right time relative to that player moving.
in a relay based setup (what I assume you are calling p2p) you typically will be going full owner authority on both position and firing things like weapons
So I need to synchronize transform syncs and RPC's?
Not sure what you have going on, but you need to have a way to replicate things
either by sending user inputs, or by sending the states involved
If you are using SNS, you can piggy back stuff on the buffer[], but that will take some digging around to sort out how to create your own SyncObj
But its designed for all of this, its what I use the system for
Anim and Transforms get synced on the tick, so you would capture weapon fire on those same ticks.
Its a shame this stuff I am making right now isn't out, because it does all of that for you
So everything worked normally until today. My project is based on Photon PUN, when i do a build, and open 10of those builds, i have 10 players on my server, +1 if i start play mode in editor, player normally joins, or i could host with editor, but today all of the sudden my builds can't see my editor and editor play mode can't see my builds. I even tested my backup versions from 15 days ago, 10days etc.. They don't see play mode anymore. It is like editor is no longer conected to anything even if i just did build from that same editor.
Set your settings to a region
The editor with PUN regularly connects to a randomly different region.
just type in eu or us or whatever is near you
@weak plinth
@jade glacier Fixed. Thank you. Idk why settings changed on its own, it was set up like that before.
np
thx @jade glacier
that was extremely easy do
i kind of understand what I did but it works great ๐ thanks a lot
I fixed the first problem now with the bullets
but now the barrel of my tank has a crap ton of laag and changing the values helps a bit, but not nearly enought.
it laags behind so mach that the bullet spawns in a completele different place
is there a smarter way to do the rotation of the barrel (it follows the mouse cursor btw)
Where can I find like examples of backend architecture for games, like lets say generic FPS.
My current questions;
Do they usually only one database for users, items, etc, or split them up?
What different separations do they do(login, heartbeat, database etc)? And what are usually on the same machine?
This is my current idea how it might look at least ๐
Player information should be separate from user information if you ask me
What i mean by that is do not store personal info in the same database as game info
Imagine if someone found an exploit and got into your game database, welp, thats a lot of user information breached
But if you tun a localhost ONLY database server that stores user information, then the only way a breach could occur is if there was an exploit in the server machine itself
I just came here to say I do not enjoy MLAPI at all
Friendship with MLAPI has ended Mirror is new best friend
Another way is to just not store User information at all, but let a third party deal with that, like Steam, Epic, etc. That you only associate, say, a steam id with a user, and nothing more.
With the rules around sensitive user data today, that's the safest bet
You can then get an access token from steam on the game client that you send to your backend, and can use it on the backend as a safe access to your user's game data as well (using Steamworks API on backend).
The downside is that you need to support one auth pipeline for every platform you want to release on.
If you can, don't store user information. It's really easy to get it wrong, and one data breach and you're done for.
@jade wharf The interface is through php sanitizing inputs. And server code is not shared with clients. So users on DB will be localhost, if that's what you meant? Userinformation will be username, email, hash. You still think I need to put this on separate DB?
@stone oar Would do that, but don't want to bind the project to any third party store like Steam, Epic etc.
Can also just bind a service like Google, and use them for the auth service on backend.
and not really store any sensitive information. The most sensitive thing is passwords and emails in combination, as a lot of users don't use unique passwords, but reuse the same ones all over the place.
I'd just treat it like any "backend" problem in programming. There's so much integrated these days for both ASP.NET and node.js/javascript world that its relatively easy to give the user the option to authenticate with their preferred service, whether its google, facebook, github, twitter, whatever
as long as you don't store passwords, you've passed most of the fuck-ups you can do with a user's data.
you've passed most of the fuck-ups you can do with a user's data.
Lmao, no
A user can request to have all of their data removed from your system at any point in time, by EU law
Just one example
@stray scroll if it is as strict as possible you might be fine
you never really know when someone is so dedicated, to steal
@jade wharf It's really trivial with todays framework to secure a DB
There's no reason that somehow your game-info database would leak information sooner than the user data
A database should never have direct access to the internet in the first place
This session will focus on Multiplay's new matchmaking service that allows developers to create their own custom matchmaking logic. Find out how matchmaking ...
@weak plinth thats what im sayin
but you would be surprised how many database source code i see binds it to 127.0.0.1 instead of localhost
hence, if a port is open on the router, and a computer binded to 127.0.0.1 and at that port. it will recieve it
am i mistaking a another predefined?
hold on
yea im right
no
127.0.0.1 allows all interfaces
weird. the source is wrong i guess
which also means im mistaking for another predefined :d
im not sure if binding to multiple ports at once is a thing
i havent seen it if so
would be kinda weird
sending to ip:3000
and ip:3001
and have it go the same place
Why is that weird
seems redundant
exposing more holes for no reason
That's not how any of that works
you missed the part where i said for the same thing
A webserver has multiple ports bound
A protocol is not explicit to a port
isnt it explicit for webservers?
No. But your browser will use 80 for http by default
right
But you can run http over any of the 65k ports
Ehm
The only reason you don't have to type :80
Is because your browser does that by default
I think you misunderstand a lot of things about networking
who in their right mind wouldnt make their webserver use 80 443
whatever you think my dude
i clearly have no idea after writing an entire physics engine with deterministic networking
Based on your comments in the last 30 minutes, I'll hold my heart about the quality of that, in terms of network at least
fucking kek
Or you used an existing network layer
i make one mistake of 127.0.0.1 vs 0.0.0.0 and you want to question all my experience
xD
binding more ports to the same service is redundant
and exposing more holes than needed
And yet, it's a thing that happens
yikes dude
So is https
And they are protocols as well.
at most i would call it a transport layer
UDP and TCP is transport layer
ok. lol.
It's not only your localhost that you are mistaken on
you arent understanding what i am trying to say
It doesn't matter. You are wrong
sure thing friend ;V
I mean, this information isn't exactly hidden
ok, maybe this is the best way i can say it.
TCP, being used as the back protocol that runs HTTP/HTTPS, which is advised to be binded to the ports 80 and 443, yes its not required, but YOU SHOULD bind them to those. is yes being used as a protocol. but it is SERVICING you the website
is that a good enough explanation of what i am trying to say
You should not bind them to those. Only if you are running a web server
You can use http/https for far more than just websites
why would you be using http/https for anything but a website
sounds like a lot of extra data size
Because the protocol is convenient
sure, fine use it for anything other than a webserver
i just wouldnt
jeez that was such a massive argument over something so trivial
Not really. You should be less dogmatic in these things
http is a protocol. Nothing more. It shouldn't be on any port
then it just comes down to a developer disagreement
i wouldnt use http for anything but a webserver
and that is just a choice
It's a very reasonable source for a rest endpoint
Which doesn't have to be a webserver
so i was making an fps then someone told me making it multiplayer was hard does anyone have an up to date tutorial on how to do this that doesn't use unet i was following along with this but its out of date from what i read in the comments https://www.youtube.com/watch?v=-m28axeuRNs
We start adding multiplayer functionality by setting up a NetworkManager and spawning the player on the network. โ Download cool Weapons: http://devassets.co...
ooof, old UNET is being deprecated afaik, and new DOTS based UNET is not there yet
so what should i do in the meantime just work on mechanics and backbone of the game and implement multiplayer capabilities later? would i basically have to rewrite everything when it is released?
Yeah, that wouldn't be a good idea
I guess you could still use the old UNET if the project isn't too big
well each instance is only going to have 32 connected players at a max 16 players and 16 spectators
that's pretty big ๐
sooo unet is def not what i want to look to do for now
Well, old UNET is still here
Personally I'd use some third party stuff
I wrote some barebones networking stuff with DarkRift2, it was fun
buuuut it's a low-level API, so it takes time and effort to develop stuff
im looking into pun and photon right now. i barely know coding so writing network coding from scratch would be to much for me
Yeah, maybe Photon is better then
Although I don't know if it's free
Anyway, for prototyping, UNET HLAPI would be good enough
alrighty thanks
If you do your game right, you should be pretty abstracted from the messaging layers
Focus while getting started on actually producing a game sim that works on a fixed tick, and consumes inputs before simulation, and stores states as a result of the simulation.
Most of what the networking libs should be doing is just sharing those inputs and states.
B-but writing your own messages is fun! ๐
@jade glacier thanks for the input ๐
So, the thing is
There are multiple API's available, from low to high level
The higher level, the "easier" it is go get your project up and running
But at the cost of control and performance
@orchid nest
And the additional thing about FPS games is, they are extremely-real time
You can't have delays or inprecise handling of user inputs
This is one of the mechanisms they use
But honestly, FPS games are crazy business. They still go "wrong" for even big developers
It's really difficult to find a balance between fair and precise
You can just say f* it and manage it out of the box, but the greater the RTT becomes between clients, the more noticable it becomes
okay so i wanna try and emulate something that seems fair precise doesn't seem fun and its all about a happy medium my biggest issue is invalids. if you've ever played rust you get the hitmarker but no damage is dealt no fun lol
Yeah, but other problems arise at that point
So suppose you shoot someone just before they go around a corner
On your acreen you hit the player, so you expect damage, right?
But by the time the data is processed, on their screen they are already around the corner
So now what?
Are you allowing person A to shoot through walls essentially, or person A to not to damage at all?
Many Halo games also had and still have issues with this
Where you either not to damage just as someone goes around the corner, or you get shot through the wall from your point of view
Hey I have a problem can anyone help
Ask
If you do local co-op for steam, maybe you don't have to ๐ https://www.pcgamer.com/steams-remote-play-together-will-introduce-online-support-for-all-local-multiplayer-games/
@robust yacht But to be honest, I think you need to expand your question a bit more, or do some research on your own at first. The most low level way to answer your current question would be to say ; "By transferring data between your users.". Then there are different ways to deal with it depending on your game. Client-server FPS, where server decided what is happening, ie. has authority, would generally take inputs from all clients, and send the world state from these inputs to the clients.
Step one: Do tutorials for a a few of the libraries so you start even thinking about networking
yeah
var handle = GCHandle.Alloc(packable, GCHandleType.Pinned);ends IL2CPP
if you make the computation deterministic you only have to send the inputs instead of the state
:v
for FPS you typically only need gravity, walls, and floors
pretty easy physics
even for 3d
Hi everyone! I am researching for a solution to my multiplayer mobile game. I was wondering what is your input, based on your experience, to my requirements.
The game I am developing is intended to use on Mobile, and is much like "Brawl Stars" game.
I wish to have an authoritative server of course, including matchmaking based on a logic I invent, and profile db savings (characters, skins, in-game currency, etc).
What solution would you guys recommend me among the current supported existing solutions?
Please @mention me so I can see the message
The upcoming unity dots networking/multiplayer packages are very interesting @weak plinth
anyone knows how do I build out server and client in new unity dots netcode?
@dapper tusk what do you mean build out?
Basically I have the new networking running, but I want to have or atleast test on two devices, how can I made a client build and server build
because right now I can only test in editor using PlayMode Tools
Hmm, I think if there isn't an option yet at top to build. I would use the Defines for client/server then build player. But if I remember it got me compile error last time I tried, not sure if they fixed it : )
No there is not any option there, I will try that later and see where it will take me ๐ thanks
@mellow beacon Thanks for your reply! But, when is it released?
All I could find is the old deprecated documentation.
Is the new network released? Can we use it and develop for production?
The preview packages ship with 2019.3
Can you link me to any tutorial @mellow beacon ?
Does anyone know how to make a in game kinda fortnite lobby
A pre game lobby
A pre game lobby
What is considered "best practice" when communcating stuff from the client owner object to the server, for dedicated + client-host, code wise.
for example
Client A calls a Method that should be executed on the server, for example DoSmth();
DoSmth(); gets executed on the server and calls the same on all other clients, replicating the stuff to the clients (for example, changing the name of the player)
So, Client A calls ChangeName("myNewName");
Server sets the new name for this object on the server side, and uses RpcChangeName("myNewName"); to change the name of that object on all connected clients
If the server is a dedicated server, it executes it on the server, and on all clients once, fine
If client A is also hosting, it invokes ChangeName(..) on the server side + once again via RPC on the client side
To "fix" this, would i just check for that case and then exclude Client A from the RPC call to the clients, or check inside that "ChangeName(..)" method if its client and server, so, basically hosting + self playing (not dedicated server) and just dont do it then.
but then i have some more boiler code
Is this the "unity way" of working with some higher level apis for networking?
If anyone has an opinion or suggestion, pls ping me so i see it tomorrow
@barren pebble i would run through the Mirror tutorials to get a better handle on what to do
@robust yacht in game lobbies are pretty complicated, you kind of need to tackle matchmaking first, maybe start with something like Google Play's game services to see the scope of the problem
@weak plinth brawl stars is pretty complicated, but i think you should try to prototype using Mirror
@weak plinth @orchid nest unity isn't a very good platform for FPS games, you may have better luck modding a commercial game
What are you even talking about? So you are suggesting it is better to mod an existing game than even attempting to make an FPS yourself?
That was strange...:)
And FPS is such a vast genre (with different netcode strategies suiting better depending on the game: competitive low-player-count fast shooter vs battle royale vs survival games).
The guy he was responding to (Dot) wants to make something similar to Halo
And in that case, networking is pretty hairy
But ya know. Someone is saying Unity isn't good for FPS, and in the same comment is recommending Mirror to people
Yeah, netcode is NOT easy at all (there's no silver bullet, there's no perfect formula), but I assume this channel is for both beginners and experienced people alike (so I expect more experienced people to be able to recognize the kind of questions and write real useful comments).
Even if the question shows that the person asking might be underestimating the effort needed, we have a choice between three options:
- Rant
- Give simple, but not exactly good advice;
- politely help that person ask better questions;
If we are here to help, there two valid options...:)
Anyone know if mirror networking will work with ECS?
It doesn't
yeah didn't think so...
You might need your own low level network stack for that
No idea if there are pre-made sollutions available at this moment
oh well, worth a shot lol
@jade glacier Knows a lot about pre-made sollutions
This is made for DOTS https://github.com/Unity-Technologies/multiplayer
Does anyone use MLAPI ?
๐คฆ
@weak plinth For what reason should com.unity.transport be bad?
I would tell you if I knew exactly why. I just heard people say it's bad.
Don't know if it's true or not
i try to recommend stuff that people actually use, to some extent, or at least has support from a community, for people who will get as far as a single process == a single game
@barren pebble it depends on what your objectives are
@weak plinth yeah, i think if your goal is to make a networked FPS, for example, or something like rocket league, which between those two features i've described all the top steam games except dota 2, civilization and football manager, unity, DOTS included, even 3 years from now when it is more mature, it's going to be an ill-fit for that kind of game
most shipping FPSes have some legacy to them, using prior commercial FPS engines, it's not at all unusual...
for the purpose of intellectual stimulation, yes, implementing an FPS in unity is doable, it just starts to look like DOTS to a certain extent
it's just an audience of, well i start a unity server process on a windows machine, and other windows clients connect to it... there aren't any networked multiplayer games that work like that anymore, except maybe paradox and civilization
so even for the purpose of intellectual stimulation, to learn something appropriate, it's very challenging to conform unity to modern practices
if you're making a turn based game, i personally think you're going to get more mileage using a web technology for your backend, i.e., use a unity client and interact with the hosted games via HTTP websockets, executing the game logic in a stateful web server
Yeah, just no to everything
According to this, there's either rocket league or turn based games
You do understand that you can perfectly make smaller-scale fps games right?
It's prefectly do-able to create an fps in unity that can host 16 players pvp, as the total traffic and cpu will be next to nothing with only 16 entities
And http is pretty terrible for games. Talk about eating bandwidth for no good reason at all.
At least suggest tcp over something like http rest for a damn game...
It's absolutely absurd to suggest someone isn't able to make something like rocket league, where mind you, you have something like 4-6 entities + a ball in unity
A server that hosts one of those games can run on a rpi
You are not going to require top-of-the-line performance unless you are synching many many entities, such as a large scale multiplayer game or a service that hosts many clusters of games
Rust can run 100 players fine with their setup. Sure itโs probably very customized...
yeah i think your'e right too @weak plinth ๐ there are lots of good choices fortunately
The more performant and real time you go, the more you want to stay away from any ML or HLAPI's
"it's just an audience of, well i start a unity server process on a windows machine, and other windows clients connect to it... there aren't any networked multiplayer games that work like that anymore, except maybe paradox and civilization"
Fortnite, PUBG, and so on basically every game made with UE4?
Yeah, you can build the headless server to run on linux machines, but same can be done with unity AFAIK.
@amber trench
There's 2 types of servers. In-engine, or without
I'm not saying this particular architecture (traditional clients---single-server, either using state transfer or snapshot interpolation) is a silver bullet...
But it's a valid approach.
And the latter is pretty rare
I don't have any survey to answer that @weak plinth
In-engine servers are vey common, yes, because of source engine, UE4, etc
and all the modding community over classical FPS
But if you think about basically every MMO, destiny, etc, these are not in-engine servers
You don't need any survey. If you don't use an in-engine server you need to simulate all the constraints for running the game somehow
Yes, I know that.
I don't know all of them of course.
But have some inside info on some of them (NDA prevents me from saying much)
I'm extremely doubtful
Without engine, you will have trouble with basic things like collision detection or pathfinding of AI
Well... Define engine..::)
In that you are right...
Makes 100% sense to share/reuse codebase between what runs on server and what runs on clients.
I'm extremely sure that, even very custom sollutions run at least a physics engine on-server.
And that's also probably all you need
But an "engine" to run an MMO is extremely complex, and it's not as simple as a "headless" server you build from a simgle C++ project like UE4, etc.
You can circumvent all of this, and make some really crappy solution where you let clients to the phyhics bits
"least a physics engine on-server."
I tend to agree with you here, yes.
"crappy solution where you let clients to the phyhics bits"
Depends how you do it...
Running part of the physics on clients is actually a benefit. This is essentially what any prediction engine does
Unless there's a physics engine on-server, there is never a good way to do that
To give immediate feedback.
"Unless there's a physics engine on-server, there is never a good way to do that"
Deterministic Predict Rollback does it...:)
Not at all. There's still a physics checks on-server to determine the rollback
You can argue that running a master simulation on server to achieve authority on game results is needed.
"Not at all. There's still a physics checks on-server to determine the rollback"
No...:)
Not needed... You only need the server sim (or even a deferred re-run of the game) in case you want to validade the results (and you can do this post fact)
Disclaimer: I'm the developer of one of such engines.
So then, according to you, how do you prevent people from walking though walls
The only data that is sent over the network is your input (movement intention, for example)
you can TRY to modify your own memory to go through walls.. Good luck with that. That's what happens:
- on the other players machines, you're just naively facing a wall (and not going through);
- constant checksums flag your game client as a potential hacker (in the server);
- your game result will be ignored (or the match will be flagged for auditing/deferred validation - based on server authoritative input stream)
No way you can do wall hacks, speed hacks, and similar... Unless the dev does something very stupid.
I'm waiting for the rollback part
Rollback is local
It's your game client's role to rollback (the framework performs that, based on the server-confirmed inputs)
Rollbacks are performed based on input mismatches (server never has to send physics data).
That's essentially how all fighting games are done, BTW
At least the ones with good netcode...;)
Traditional client-server is just one of the safe models for netcode (it's awesome, and server well several game genres, of course)
How does the server know to confirm inputs if it runs no physics at all
Server doesn't need any physics to confirm input. It's all based on a synced clock (from server) constant tick-based input stream.
Server needs to validate that game clients send input for every tick within a configurable aggressive time-limit
Any client that fails to do so has it's input for a particular tick reset as a zeroed-out one (or with the same as prediction config determines, but I'm trying to simplify the explanation)
For physics based games, deterministic predict rollback is arguably the best solution (I'm not trying to be a know-it-all, I apologize if I sound like that).
IMHO, it's your game (mechanics) what dictates which netcode strategy you should use (not any preference, or tool advertisement, and not ME as well).
I personally like all of the different strategies. I'm particularly a fan of the Destiny's distributed model.
I'm pretty sceptical about the implications of authority in some use-cases
You have the right to be...
Would you mind giving an example?
Of authority issues
(I'm always evaluating these myself).
Person A shoots person B
Person A claims there was no wall while person B claims there was a wall
The server has no knowledge of physics
There's no claim
Server MAY have the physics
OR you can re-run the full game sim post fact (as I mentioned)
We're talking about a use case where the server has no physics
Well, deterministic predict rollback is a model that lets YOU decide not to run the physics on the "expensive" real-time servers...
But it still gives you the AUTHORITY to check match results post-fact.
So authority might be needed on platforms where cheating is prevalent
IE a non-physics server is not always viable
But you don't need to pay expensive servers to use a lot of CPU with physics for ALL matches (PS4, Switch, iOS, have very little cheating going on)
There's also the case of difficult-to-mod on consoles
"IE a non-physics server is not always viable"
Predict Rollback Determinism gives you this as a choice... You use it only for the matches where it is IN FACT needed... So saves you (a lot of) money.
I'm not arguing with you that authority is needed (in some/many cases, arguably). I agree...
It's just an interesting model that gives you lots of interesting tooling out of the box (full match and killcam replays are part of the engine, you don't need to implement anything crazy)
I'm sure there are other developers in this channel who are familiar with it.
The model (not the particular product/tool I work on)
The model is a pretty known one
IMHO, the extreme popularity of FPS games might be the reason why their particular netcode models (there are more than one, but almost always based on the classic client-server) are the ones people tend to recommend.
They are interesting, and certainly safe models (although more expensive). But they are far from the being best models for all game genres (or the easiest ones to work with).
There's never one-size-fits-all in networking
But this is just my opinion.
yeah
That's why I like so much when a team comes with something interesting and different (like destiny's distributed model)
And even in the exact same game (hypothetically), you are probably going to make a difference in model between 16ccu or 128 ccu
ccu or player count in a single game?
(at least here) we refer to CCU as the total sum of concurrent players you have in the game (not in a single match).
Assuming ccu = players in this case
"model between 16ccu or 128 ccu"
Assuming in a match, of course.
My point being here that there's more leniency in terms of perf with only 16ccu
You can also go with a model that's very fast, simple/elegant, which is snapshot interpolation (same as CS-GO and Unity's fots FPS sample).
But this model doesn't scale if you need 32+ players, or lots of destructible parts...
Then you probably goes better with state transfer (with scoping, culling, priorities, etc)
Which is what is used in Battlefield, Fortnite, PUBG, etc (AFAIK)
Overwatch (state transfer + local predict-rollback) and Apex as well.
I rather go with state transfer myself in any case because it makes more sense for me
It's more felxible, yes
But also a LOT more complicated to implement, with lots of edge cases.
Not everything has to be easy ๐
Yes, sometimes a forget how complicated this is. I mean, developing games (properly) is difficult. Online multiplayer is arguably 10x more difficult.
Definitely
Anyway, back to work here. Nice chat.
Feel free to ask anything about deterministic physics if you wish (not necessarily related to the product I help develop, I'm always interested in physics + netcode in general).
I have many questions. But I'm busy with 50 other things currently
๐
Good to know that I can ask in any case!
Hello, just arrived, got a question: is using a Idictionary o Enum and Funct a good way to implement handlers for data packets events?
I'm trying to find an alternative to the big Switch implementation
That's something you can do. But it's a small overhead
Performance wise, there's nothing wrong with a huge switch
IMHO you can start with that, so you can implement the features...
But performance-wise you'll probably end up with the big switch later on...:)
isn't the switch more expensive
no
Not at all
in terms of computation?
way faster actually.
?
jump table? doesn't ta switch have to parse always all the cases?
Instead of a dictionary lookup and a virtual function call for the method
No. Why would it? The values are constants afterall
There's a faster way, depending on the language...:)
use the message IDs as a pointer offset... store a buffer with the function pointers...
All functionr efs will be in the cache... the pointer offset (message ID) makes the jump be performed really fast...
You could make that with IL probably
interesting
But not C#. Closest you can get to func pointers are delegates afaik
We do that kind of thing ourselves with C# (not really for function pointers though - maybe possible with IL).
And those are virtual func calls
do you know of a good library I can use that has this approach implemented?
Yeah, you can do it with delegates
I don't think that is really really needed
You can also use an Array of functions.
But that's going to be probably a fraction faster than a switch (although it'll look more consise)
That's slightly slower than the pointer approach, but works in most languages.
Array of functions, you mean delegates I assume?
that's why I thought of sorted dict (with enum) and Funct<T>,<T> as value... there is no lookup if it is sortedd and the CMD of the packet is calling the respective Enum
For very long function lists, I'd actually do a performance test..::)
guys you are going bacjk to what i was proposing
I'm not
No, I'd not use the Dictionary approach myself..:)
is faster a sorted dictionaty
No
I doubt
then having to use a fixed lenght array
Definitely not
Just do a proper test with a stopwatch in bulk numbers
Array is going to beat a dict any time
Dictionary vs Array vs Switch vs Pointers (if possible)
IL is likely going to be the fastest, then switch, then array, then dict
and an Enum tab as offset
I'd expect the pointers to be faster (but not easy/possible with C# directly)
you mean Ilist?
No I mean array
really old fashioned array []
ok so you agree this is the fastest implementation for CMD handlers? (is this the right definition)?
There's a very basic reason why array is faster than Dictionary
Yeah, no lookup
No extra function stack...
a Dictionary lookup is an extra function stack created... Array lookup is just a memory fetch
there is basicly no lookup in an hashtable of a sorted dictionary
A dictionary isn't 1 single array either
A lookup is actually a lookup
Array is access by index, which is just a pointer offset
yes, exactly
problem is that an array is fixed
I don't see a problem there
Do you really need to resize it frequently?
but is ok I guess
Don't you know the exact number of commands?
true not frequently
Because you can resize infrequently just fine
A Switch is fixed size as well
But to be complately fair. The performance difference is going to be negligable between all of these
a switch ius like concatenated IF statements... they are expensive\
Unless you are squeezing the last few % out of your CPU, none of these are going to matter
we are talking about managing network packets.... is a heavy bottleneck
No it's not
If I had a situation in which a function lookup was a bottleneck, I'd check between the array vs switch (write a few performance tests, use IL2CPP builds on actual devices).
To both of your comments
If distributing of packets is in any way a bottleneck in your game, you've done someting terribly wrong
And a switch is NOT a bunch of if statements
I'd not even consider the Dictionary IMHO.
Well, for THIS use case, I think the Dict would not be that bad on a CLIENT.
On a server... Another story..:)
Neither on a server, comon, let's be real
Not unless he's planning to run a few hundred CCU
thats the idea
thousands is a completely different story
I'm thinking you shouldn't even be touching C# nor Unity at that point if you ask me
?
Native/C/C++ in that case
come on you don't neet to go down do C++\
We have a tiered server
When you have thousands of CCU? You definitely need to go down to C++ or lower
If only for the more consise memory management
my guess was that avoiding the switch with a good multithread implementation gets alreaady a 10X
No
It's not even going to be x2 vs a dict
Probably not even x1.1 lmao
In fact, a switch is probably faster
Likely*
good multithread implementation
As well, yes... But this is not as simple as it may sound when dealing with xK ccu per machine
ok I agree the array could be better here... so shall I go on with the array instead of the switches?
There's nothing wrong with a switch
Anyway, for your use case an Array would be just fine, maybe even the sorted dict
Or a switch, lol...:)
a switch looks so bad to look at ๐
Agreed..:)
And jamming a collection full of delegates looks so much better? ๐
do you guyss have a good library to suggest to get inspired from?
Because books say so...:)
Well, unless you use reflection to fill your function collection at startup
That might not be a bad idea
delegates are resolved at compile time or I'm I wrong??!
define resolved
the pointer is resolved at runtime, as you can set them
just the signature is protected by compiler
really?
A delegate translates directly to a virtual function call
So resolved in runtime, correct?
If you are questioning me what happens during JIT, I have no idea
I just know that in IL a delegate is a virtual call
I mean I think is in this way by definition
thats why they are compile prooof I think
Just like delegates
an array of funct is an array of delegates pointing during compile time to the assigned Static handlers in my case
or I'm I wrong?
tahts why it gives an error during compiling
if there is no reference
during creation of the array
a delegate is a pointer to a function
You can reset it during runtime...
no NEED, but possible
not sure if there's a C# keyword modifier that would force it to be statically resolved.
Vs a function call
so reaching the Value of an array by index is way better then using a switch... and a more clean implementation
The overhead is the fact that it's a virtual function call
you can't create an array not statically resolved in my case
it is not a virtual function call is a pointer
Yeah, that's more expensive than the difference between array and switch
to a static method
yes, but delegates are implicitly virtual functions
So they get very late binding AFAIK.
virt call takes twice as long about as a normal
if we don't agrre on the fact that what ius resolved at compile time doens't affect overhead I guess the whole thing makes no sense
You keep saying this, not me
if we are not sure about this I guess I'm getting just a bit more confused
It's a fact that a delegate is a virtual function call
And that takes twice or more as long as a normal function call
if you are sure about this then I learned something new
Also virtual function calls cannot be inlined
Checked here
delegates, as @weak plinth has said are essentially syntax sugar for an interface/virtual functions.
Ok
You can see the difference between a virtual call and a reg call here
this isn't IL but assembly
I will defenitely read this
Nice ref...
do you have a ref to a god library I can read that does something similar to what I'm doing?
Not only are the 2 function calls inlined without virtual, but all of the checks and memory moves etc are gone
No. But it doesn't take long to make
I mean, it does. But that's use-case specific
there is different ways to implement it and I could not find a good match yet
The only way you are getting away with this without much typing is by using codegen
Like T4 templates or whatever
and crafting from 0 as I'm doing is a bit time consuming
And notice we're already a lot beyond the original question (dict vs switch)...
Unless you want to do delegates, in which case you can use reflection at statup
The late binding/resolve is an extra optimization...:)
But as I pointed out, you aren't going to need any of these optimizations
And if you do, better go to C or C++ instead
Not for message handling at least
Serialization takes infinitely longer than message handling
I need to be aware of these things because I have functions that are called thousands of times per TICK...
Just to name one example of the chain
Yes, serialization will be a much more important topic for you.
Specially if you plan to do scoping/culling/priorization (state transfer), or even just delta updates.
Could you advise about a very good serialization library?
Write your own
My very own ๐