#archived-networking
1 messages ยท Page 93 of 1
It won't be valid until OnJoinedRoom has fired
alright, I'll test this later then, thanks!
I saw on a forum that it was internal Unity bug with the input system so I just remade the input asset and now there are no errors, BUT the jump system just doesn't work ๐
how do i sync rig layers in photon pun 2
Extremely Entry-Level question here, but i'm looking for a networking solution i guess? Something that would allow me to take a game and create "servers" in the style of Runescape / Rucoy (Android mobile) / Curse of Aros (Ios mobile) / while having either a webgl player / mobile app.
Any leads on packages / leads / etc that are available nowadays i'd appreciate.
I can't drag and drop a script component into the Observed Components on a Photon View component, does anybody know why?
using Unity 2019.4.13f1 and PUN 2 - 2.25
it does yeah
oh nvm, it is working now! I just deleted the component and add it again
and suddenly it worked, thanks
you can just leave that on autofind
The whole manual drag and drop is just for backwards compat.
@worthy gale
Or hit find, same outcome.
Yeah, just figured that! thanks ๐
some 1 help me why wont my bullet spawn
pls
idk why
also how do i fix an error it says server not active
im using mirror
Can anyone look at my code and tell me why my character isn't jumping? I linked everything correctly with the input system, and my character is able to move and look around properly.
I'm using Mirror.
So is someone able to tell me why we make the client/server match tick rates instead of just having the client send the server packets with instructions every 0.02 seconds and not keep track of the server's tick
is it so the client doesn't get too far infront of the server or something like that?
Also when finding the RTT / 2, can I just send a timestamped packet from the server to client?
Or does it have to be client -> server -> client
I'm having an awful time trying to get tick prediction working. I'm having to predict 4 ticks ahead on a LAN connection just to have them arrive on time
3 and under arrive too late
Currently I'm just polling for new items on the queue in my fixedupdate, which is what's causing it to run so slow
I don't know how else to check for new info without polling
can some one pls help me when i spawn my bullet i get this error: NetworkServer is not active. Cannot spawn objects without an active server.
I have seperates scripts for my weapon player and bullet my weapon is a child of the player but it doesnt create the bullet all the weapon does it call a function inside the player and lets the player spawn it in i dont know whats wrong since im fairly new to networking.
Hi, is there someone that can clarify my custom network protocol? I'm using python non blocking TCP/UDP sockets in server side, and in client side i'm using TcpClient and UdpClient classes. My game protocol uses only hex bytes to communicate, with this packet structure: PacketIDbyte + BodyLengthBytes + BodyBytes i'm parsing every packet using Reflection and generic types, with BitConverter, Encoding and Array.Copy i'm doing all the serializing/deserializing in client side. Everything crucial is surrounded by a try/catch that should "properly" handle the exception.
I'm not concerned about the serialization/deserialization part...that seems to work pretty good!
I'm using TCP as the reliable game server, that should handle lobbies and players, while the UDP server is primarly used for forwarding players status packets in an active match.
About the status packet...
The status packet has a ulong counter set as the very beginning of the packet's BodyBytes, that gets increased every time the status "changes" ( which means another variable called oldStatus gets checked and copied after), this counter is useful, cause i can check, server side and even client side, if the new_status_packet_counter > current_status_counter
The result seems good, but if i do lots of actions, that translates in many packets x second, the opponents updates slow, if the spyke goes down for a moment, it keeps following the packets in order, moving the player slowly from the previous positions to the newest...
Obviously, i'm using different threads to receive the packets, i'm parsing the packet in Update tho, idk why it seemed faster if i do that..anyway, i forgot to mention that every time a buffer gets processed, and a new valid packet has been found, the packet goes to list, for game packets, my method to take packets from the list uses a List.Clear(), so i get the packet, and i clear all the next packets, so that i can still receive the latest one.
Sorry if i took too many lines out of this channel...
Feel free to DM me..
https://github.com/DennisCorvers/Lockless-Queue
Added benchmarks and small performance boost ๐
So I'm working on a 2D platform fighting game and from what I understand if I want to implement networking I should try and work on that from the beginning. I also know it would make sense to use a P2P connection with deterministic rollback. I've seen multiple articles on how it works, but I have no clue how to implement it in Unity. Does anyone know how I would do so?
can someone help? when someone joins it uses their texture and not yours.
https://hatebin.com/hpjeeddvnj
im using photon pun
@sleek laurel Pastebin or Hatebin it please
i'm trying to set up multiplayer for a webgl game on my website
but I don't know a lot about networking
nvm i found out
if (photonView.IsMine)
{
photonView.RPC("GetTexture", RpcTarget.AllBufferedViaServer, skinurl);
}
just had to do this
the docs say If you need to use Networking in WebGL, you currently have the options to use the WWW or UnityWebRequest classes in Unity or the new Unity Networking features which support WebGL, or to implement your own networking using WebSockets or WebRTC in JavaScript.
i suggest look into photon pun, i use it and its quite easy to use
what is ti?
@south palm https://www.photonengine.com/en-US/Photon
Global cross platform multiplayer game backend as a service (SaaS, Cloud) for synchronous and asynchronous games and applications. SDKs are available for android, iOS, .NET., Mac OS, Unity 3D, Windows, Unreal Engine, HTML5 and others.
oh it's a unity package?
yeah
Not really, it's an asset made by Exit Games
i thought exit games owned photon
oh you mean not a "unity package" but "someone package"
@grim violet Can you explain to me why the client needs to sync his tick with the server? Why can't the client just send an update packet to the server every 0.02 seconds and not include the tick?
I cant seem to understand it no matter how many people try to explain it to me
like I get how to do it, I just don't get WHY we do it
you could do it without marking the packets, thats kinda the base of udp, sending packets without caring, but then its just received in any order and can be hard to maintain
the reason people mark em is exactly for syncing, knowing what clients are at compared to server
So say the server decides to lag and is now 40 ticks behind, you wouldn't want the client to be 40 ticks ahead
so they would need to re-sync
?
hmmm
hence why they are marked
if server start sending 1000 packet to each client and at packet 500 one of the client lag until packet 600, he will still receive packet 600 when server decide to
but if they weren't marked the server decided to lag behind a few ticks, that would cause problems right?
if you try to sync client from 500 to 600 while he missed all this it wont work
if server lag everyone lag
alright
when you play those game where server has authority, you can see it clearly when you freeze, everything around freeze, other player too
and it resume once the lag on server stop
now if your game freeze and other arent, either server doesnt have authority or its your own client that laggued out
well if you weren't syncing the tick, and the server lagged at tick 500 for a couple seconds, and the client just kept sending packets
the input buffer on the server for that client would start filling up pretty fast
and the client would be behind right?
ok
if client continuen sending packets while no one know whats going on
it will end up mixed up
client could literally kill everyplayer while server lag then it resume, what happen
gotta stop it
yep
So when the client predict's the server's tick, about how precise should I be predicting?
the server's next tick? Or like 3 into the future by the time the server gets the packet?
So say my server is at tick 150 and it decides to synchronize the client. I'm ticking every 20ms and it takes 200ms from server->client, we can predict, on the client, that the server is now on tick 160, correct?
and then I have to predict the same way, when sending packets back to the server, to guess which tick its going to land on?
yep
well when sending back to server it doesnt matter
as your server will process latest tick?
i mean you got an order to follow on server
Wait, when sending info to the server, do I have to include the tick number in the packet?
for sure
so I'd have to predict which tick the server will be on?
did you check that Server reconciliation part in the webpage
i think thats exactly what they are showing
I'll have a look
I'm still very confused. So when the client sends the server an update packet, the server will process that update packet on the next tick, no matter what?
I don't have to guess which tick the server will be on, from the client?
well you gotta follow it close but dont have to be on the exact same tick (maybe 3 tick forward as you said, there no exact magic number as it differ with the lag etc), now if your client is ahead of 20 tick compared to server, you know something is wrong, id freeze the client until it receive the other ticks from server and get close to what you expect it to be
i have no idea of the proper way to do this but this is what i think it should be
at least thats what i see from games
alright
this sums it alot
then you add lag compensation for the delay
that website i showed sums it all pretty much, just readed it all
Hey guys. Looking for people who who like to help us build community created maps for the VR FPS Alvo. Ping me if you are interested. Thanks!
I have a 3D movement script written. Currently, I am able to move around, without gravity. Here's where the problem starts. I tried implementing jumping and gravity into my script. However, it did not work. So I decided to do some testing upon a users request, and I realized that when I click the space bar (jump key), the debug log only returned once. The ground check does not seem to be the problem.
How is lag-compensation done for finite-speed projectiles? (Or is it actually not done?)
Should the server spawn them in the past like it would do for hitscan traces, but then like fast forward them to catch up to the client?
answer is "Depends"
You have to decide which timeframe you want them in, and how to get them gracefully into that timeframe.
If you are shooting like rockets, and you want the other player to be able to dodge them and see them in their predicted timeframe, you need to time advance them for that player.
For the shooter, you may want to also try to see them in the timeframe of the other players, so you can see how much you missed by, which means some combination of inducing trigger lag, and/or lerping the projectile between timeframes - for example leaving the barrel a little late and flying a little slower than actual speed.
You aren't seeing "reality" but the goal is to make the object as best as possible get into the desired timeframe.
You don't typically spawn them in the past on the server. The server is the keeper of "reality" though, so all that matters is that everything respect its authority in the end.
all of the pushing time around for the projectile is just cosmetic.
So to the point on enabling other players to dodge, do mean like someone fires a rocket and everyone starts extrapolating its position?
They know when they get the "fired" message, that it is late. How late can be tricky to nail down, but its basically 1/2 RTT from the shooter to server + 1/2 RTT server to dodger.
right
You are lining with the server if you aren't pushing time around like you are talking about doing.
in which case, the delay is just 1/2 RTT
The answer varies depending on what you are doing with the server/client authority over this
But whatever the number is, the client who is dodging knows it is seeing the past, and it needs to try to get that projectile into its predicted timeframe
So it advances its travel by X ms
There is a balance there as well though, if that missile hits some other player, they won't see that right
Because the other player is in the past, and the projectile is in the present for that dodger
So there is never a perfect answer in state transfer with prediction
Can it be done fully server-authoritative? Like not needing any client to send a message like "hey, I think that rocket hit something."
This is fully server auth. The issue is prediction
The server sees reality. The issue is you as the player are predicting your own actions
you can not do that, but your input lag will be henious.
Fully server auth means you send inputs to the server, and you wait for your resulting state.
Only way around that is insane good pings, like Stadia depends on.
Right, I think I just need to think over what you wrote a bit more. I'm not sure which timeframe I want things to be in.
This is all just talking about state transfer with prediction. The rules change when you get into lockstep, extrapolation, and determinism.
As long as you get the concept of the timeframes
Prediction lets the player do things immediately, but that puts their actions in the future of what they see around them.
They are eternally in desync
Yep, I think now I've got a pretty good grasp of those fundamentals and like maintaining clients at the right lead ahead of the server based on their ping. I just got stuck on this rocket thing.
On a somewhat related tangent, say I have the client predict firing the rocket but I actually mispredicted (got stunned). Is there a generic way to undo locally spawned entities? I guess if I'm sending snapshots I can just overwrite the whole state and they'll disappear.
The rocket thing is a good exercise in figuring out how to deal with hiding the paradox
That usually falls right on the game dev to figure out how to resolve
This isn't deterministic though
so the server is the final word no?
you just mean how to unfire your rocket locally?
yeah
That is a cosmetics problem
that rocket isn't real anyway
predicted weapons should be considered to be entirely cosmetic, they do no actual damage
So you could just make it disappear, and mask it with like a screenflash or effect from when you got stunned.
that makes sense
For projectiles, I keep a tick record of them, so when the server comes back with the state I can map that to the object
That is useful if you intend to shift the projectile you predicted into the server timeframe... you need to know when the server finally got back to you confirming you shot it.
And same as with the other clients, you use that to determine where it actually should be, and lerp it into agreement.
https://drive.google.com/file/d/0B7wLFN2dg2IRVzBnTEMxQWJkbDA/view?usp=sharing
This was my first attempt in networking and it dealt with that.
You can see the bullets change color as they shift from white (shooters timeframe) to green (lerping into agreement with server) and red (in agreement with server)
Hey, So i am using Mirror for my networking and i have an issue.
The methods tagged with [Server] are throwing warnings on clients.
[Server] function 'System.Void Class::Method()' called when server was not active.
Why is this happening ?
AbilityBehaviour : NetworkBehaviour > https://hatebin.com/ddbqhailwa
Fireball : AbilityBehaviour > https://hatebin.com/aypjiqzbyk
i want server to handle it completely, but when i cast a fireball, all of them throws this warning.
Also i instantiate the fireball with in [Command]
@midnight bane this might be your problem
https://forum.unity.com/threads/when-does-codes-marked-as-server-gets-called.362585/
Hi, how do u do server side profiling?
I dont believe i can just input my server ip into the unity editor profiler, can i?
is there something i am doing wrong why am i getting this error get this error when i run it on a vps. please @ me if you may know the reason why its unloading.
So I think I get it now.
Future Present Past
How clients see themselves What the server sees How clients see each other
Client A fires a bullet at Client B. This bullet is cosmetic and half-A-RTT in the future.
Half-A-RTT later, the server spawns the real bullet.
Half-A-RTT after update is sent, A gets it and interpolates its bullet backward by half-A-RTT.
Half-B-RTT after update is sent, B gets it and extrapolates its bullet forward by half-B-RTT.
(We account for interpolation delays too.)
Basically "meet in the middle" and have both clients observe the bullet near its "present" position.
Is this what you meant by align with the server?
And to lag-compensate on the server, it needs to "fast-forward" the bullet somehow (interpolating its velocity?) otherwise I'd have to keep looking at old snapshots of the world to check for impacts.
I would consider what the server sees as "Reality"
What the server sees is the only correct picture of how things are relative to one another.
All other clients see a mix of their future timeframe for their predicted objects, and "past" - which is the "Reality" of the server that gets to that player after the fact.
Sounds like you are thinking about it right
Client A fires a bullet at Client B. This bullet is cosmetic and half-A-RTT in the future.
You may be getting into the realm of where server shot rewind comes into play
for shooters, when a client predicts shots, you want them to hit what they think they hit, even though in reality they are missing like mad because they are shooting at the past. How games get around that is by having the server rewind the players and their targets in time to make a guess at what that shooter saw when they fired, and tests the shot against that.
The other alternative which is more risky in terms of cheating, is just trusting the shooter's hit claims.
The handling for slow movers like rockets will be different than hitscans for this reason
You can't timeshift to hide the paradox... its instantaneous with a very fast bullet or hitscan.
I understand that you can't avoid the paradox. Like, okay, for hitscan, compensating by rewinding all the hitboxes and doing the raytrace there in the past is the clear solution because you know if you hit something, the ray is instant.
But for a moving projectile, AFAIK the server can't tell when that will hit anything because stuff could happen later (another client jumps in the way or something).
That's why I'm asking about "fast-forwarding" the projectile on the server. You either rewind the world back or advance the moving object forward, but doing the former, i.e. waiting until the projectile hits something and then rewinding seems like it could playout incorrectly.
For slow movers I would just let the server run things normally
And you make the clients deal with trying to shift time as needed to make it cosmetically give the right info to players
So on the server, when it gets the fire command, it applies that on the appropriate simulation tick and just moves the projectile normally.
Is the "appropriate simulation tick" the tick of the fire command or a tick in the past?
I don't know what your system is.. how ever you consume inputs from players... just do that normally
Apply weapon fire the same way you apply movement inputs
After a while, I got my movement system to work, with movement, jumping, and not being able to jump when you're in the air. However, the new problem is that no matter how much I change the gravity value, the character always falls down at a ridiculously slow rate. Did I do something stupid in my code?
Movement Script: https://hatebin.com/qtsgpgqaew
^^ Mirror, although I doubt that matters since I don't think the issue has anything to do with networking
that sounds like something in controller is clamping the velocity magnitude.
It probably doesn't help that you apply gravity twice.
Ohhh you're right I do apply it twice I'll test what you mentioned when I get back on my computer thank you for the response
oh, i had another look and realized that
if (groundedPlayer && up.y < 0)
{
up.y = -2f;
}
is probably the culprit
What's wrong with it?
it wont fall much faster than 2
cause it's -2 + (-15 * Time.deltaTime)
but... i have no idea how CharacterController works.
Ohhhhh wait you might be right I'll have to experiment with that too wow you're much more attentive than I am ๐
I just read a couple articles saying they sat down with network engineers who have worked on major games, that said you don't need to synchronize the ticks, the client just needs to send an update packet and the server needs to take it
this is so confusing
do they explain what the server do when they needs to take it
I'm pretty sure it was for a first person shooter
I'm not sure though, read it before bed on my phone last night
I have the whole tick prediction system built for my client and it works, it just seems like a messy way of doing things
as opposed to just sending inputs every 0.02 seconds and having the server process it
but there's so many problems with the second option
> Why can't the client just send an update packet to the server every 0.02 seconds and not include the tick number?
Because then the server wouldn't know what tick an input is for?
If you send a sequence of packets across the Internet, some will get lost; some will arrive in the wrong order; some will even get duplicated.
If you send those packets completely unmarked, you can't expect the server to read them in the correct order. Given these problems, how is the server to know if an input is late, early, a duplicate, etc. unless you explicitly tell it "this input was for tick X"?
You're basically asking why mail packages need addresses on them to be delivered correctly.
So say the client lags and sends 20 messages all at once, and the server queues all of them up no matter what, and only executes every 0.02 seconds, now the client is permanently 20 ticks behind?
with my dumb no tick solution
I feel like I'm asking the same questions over and over, I just can't seem to grasp it
I feel like I'm close to understanding it though
server itself is at a certain tick, if client is behind cause of lag all those packet would be ignored
Yes, but I'm talking about a no tick sync solution
where I was talking about just sending instructions every 0.02
well it cant work
alright, that's all I need to hear
If the server just accepts inputs in any order whenever they arrive, your avatar won't move at all like you expect.
if data doesnt matter the order it come by etc and its just a flow of perpertual numberrs like a GPS or whatever it doesnt really matter i guess
Well the last solution I built, the client would order his packets with a sequence number, and the server would just drop any packets behind the last confirmed sequence number
It wouldn't even know that those 20 messages were old.
you still have an approximation on server if packet come in disorder
but its not perfect
My main concern, however, with the client predicting the server's tick, is that if he's too far infront of the server, then he'll have more ticks to process and more physics.simulate events to call during client reconciliation
maybe I'm just overthinking it
you can just flush your queue if it gets too long. Sure inputs would be missed, but lag spikes that large should be avoided anyways
Roystan, you know a lot about this stuff, my game is going to be fast-paced first person, I should use tick synchronization, right?
I would definitely defer to erick and emotiton, they both write networking libraries and have probably encountered a much wider variety of use cases
The cost of reconciling is just the cost of a single tick times however many ticks you're ahead. If you're like seconds ahead of the server, you should probably just hard snap to the next update you get from the server.
@gleaming prawn @jade glacier Just gonna leave these here. Trying to decide whether to synchronize the ticks, or just have the client send instructions every 0.02 seconds and the server processes them no matter what (as long as the sequence numbers aren't out of order) trying not to screw myself for the future of my game and you guys know a lot about this stuff.
@dense hedge Exactly, but if my client is predicting the next server's tick too far into the future, that's going to mean more of a gap that I'm going to have to reconciliate through
which means more stress on the client for however long that is
my players also move with rigidbodies, which means I might have to reconciliate pretty often
I'm not talking about seconds btw
like 10-15 ticks max
how can the client be too far ahead
So like a really bad ping is like what 300ms? That would translate to around a ~10 frame lead @60Hz updates.
I think the only time a client would be that far ahead is like when the game first starts.
@grim violet Well the client has to predict which tick the server is on, correct?
if the server dont get the response from the client, its not processed
only that client will see himself ahead
wont do much
you can still use the timestmpa on server of any of his action and know whats going on
if hes too far ahead (lagging bad), disconnect him
thats it
;p
this is such an anxiety producing brainfuck
For right now I'm using a whole tick synchronization system. So my server sends UTC timestamp of packet send, client gets it, finds the difference
calculates how many ticks have been processed
sets his tick to that
and then predicts which tick the server will be at by the time his packet reaches the server
erm
That's literally what unity does for their FPS sample
yeah, typically your buffer offset is determined by the RTT you have gotten so far
And then you need mechanisms for that to correct, to shave or grow that if that guess turned out to be very bad.
Its the same mechanism that is in place for clock drift and changes in internet quality/stability... so one system for adjusting your buffers should work for all of these issues.
So, for my first person real time game, I'm going to need to use this tick synchonization system? I can't just send client packets every 0.02 seconds and hope the server gets them?
That's basically my question out of all of this
Are you predicting on your client?
yes
Then be ready for some harsh correction in adverse internet conditions if you aren't managing your buffer size
nose bleed
So say the client lags and sends 20 messages at once (the problem I was actually experiencing)
that's what you're talking about?
That's a pretty extreme problem
I can't say really, we are talking in very vague terms. The answer is "how you coded your system to deal with this"
The answer to how your system will deal with this stuff... is how you coded your system to deal with this stuff.
My system didn't deal with it, when it was implemented, the buffer size just kept growing
so it is feasable though?
to not have tick sync?
The server should be consuming at a fixed .02 as you described it.
yep
or just doesn't do anything for that tick, like unity did for their FPS
If a tick fails to arrive, it extrapolates one.
alright
In some form
either reusing the last one, or using default values.
The server ticks at .02.... NO MATTER WHAT.
yep
does anyone know darkrift 2?
Then I don't get what you mean by "or just doesn't do anything for that tick"
is it good?
It ALWAYS does something... it simulates.
guys
but if it doesn't have any data for that tick, it would have nothing to simulate
is darkrift 2 good
@dusky zenith Homie, you're in networking channel
we dont know what that is and if its a game just google it
If no one is answering, then noone is around with experience enough to answer @dusky zenith
Simulation doesn't work like that.
there is no such thing as "no input"... you can have "default" input
or "use the previous input again" input.
But your simulation is going to fire.
Correct, but for unity's FPS, if they missed a tick, they just "do nothing" for that tick
I have no concept of what "do nothing" means in this context sorry
no input. standing still
correct
That is different than "do nothing"
alright
That is also a bad practice, but I don't think they do that.
if the player was holding down the W key running, and a tick goes missing... it is safer to assume that W is still down, than to assume they let go of all keys for that step
But if I'm just sending packets every 0.02 seconds without synchronizing the ticks, how does the server know that the client missed a tick? Does the client just send sequence numbers?
That is what extrapolation refers to.. reconstructing missing inputs or states
You should be numbering your ticks, for that reason.
you will throw your system into massive desync constantly
So if you were making this game, YOU (and probably erick too) would synchronize the client/server ticks?
just based off experience?
I'm trying to do this as correct as possible
best way to know is to test ;p
It just feels like I'm doing this wrong with whatever path I take
anxiety is always 100%
all I want is a definitive answer from a smart person to tell me which path to take
Because when I wasn't doing tick synchro, it worked literally perfectly fine until I alt tabbed the client and he lagged and started sending messages when he shouldn't
cant you stop sending message when application lose focus?
well the problem is fixedupdate, it stops sending messages then it tries (pretty awfully) to catch up with the current time
and fires a bunch of fixedupdates all at once for however long it was frozen for
at least that's what I've concluded from my tests
why use fixedupdate to send stuff?
Just thought that was correct, since my players move with fixedupdate
then the packet gets sent at the end of all of that
just gotta find a way to make it stop packaging em all
I could just flush the buffer once it gets too big like someone suggested
I just feel like I'm going to run into more issues
You are in the deep end of networking with this stuff, cheap and dirty fixes generally are going to be more trouble than help.
You just need to work up a mechanism for properly consuming your buffer so that it can dynamically adjust in size.
It sounds like the issue you ran into was that you started out synced properly, then your client stopped sending messages when you ALT+TAB or dragged the window, which messed up the pacing (client fell way behind the server), then when you came back there was no mechanism to correct that.
There should be two buffers in question here, or buffer timings at least.
There is the input buffers on the server, where the server buffers inputs to make sure they have enough time to arrive before simulating.
And then there are the state buffers on the client, which has to be big enough to give the server traffic time to arrive before the client moves to the next rendered tick.
There is a third buffer, but its timing doesn't matter... that is just your prediction state record, which you keep on the client to compare against the servers state - to check for desyncs.
Systems will vary from dev to dev, but those are the buffers you are managing.
Emoti, you have to tell me which method you're talking about here. Tick synchronization or just standard input forwarding
I'm not sure what you mean by the server's input buffer. If the client sends his command to the server, it's going to be processed during the next tick no matter what. Obviously there will be a buffer, but it's only going to need to havea max size of 2-3 inputs with my current tickrate
at least that's what I'm trying to aim for
During my testing without tick synchronization, the server's input buffer for each client would only have about 3 inputs in it maximum, until I alt tabbed and the lag occurred
Hopefully erick can give his input on this a bit later
I suppose instead of just clearing the entire input buffer if it exceeds 4, I could just remove index 0 and add the next one into it, etc
If that's what you're talking about for a consuming mechanism
Both the server and client will consume packets at an orderly fixed-rate. But any time expected packets are missing, the server or client will extrapolate from previous one it used.
On the server, if any client's input for a tick is missing when the server goes to simulate it, the server will just reuse that client's previous input. On the client, whenever it doesn't have a new snapshot to interpolate towards, it'll just extrapolate from the last snapshot it used.
Inputs can arrive to the server early, the server just puts them in a queue. If an input arrives to the server N ticks early, it will sit in that queue for N ticks, which translates to N ticks of additional latency on top of the raw RTT.
For the client, server updates don't make it through the Internet in an orderly, fixed-rate fashion. Because extrapolating other entities doesn't look as smooth as interpolating, the client wants to be interpolating most of the time, so the client will actually hold snapshots in the queue for several ticks on purpose before consuming them, just so it likely won't have to extrapolate.
The buffer on the server is per-client and its size is mostly related to how early that client is sending its input.
The buffer on the client is mostly related to network jitter.
That's the thing. In my standard input forwarding (without tick synchro) the server is going to have no idea if it missed a tick from a client
since it's just consuming the latest received packet from the client
yeah, your model is not the usual
I do have sequence numbers though, so out of order packets get dropped
if the sequence number is less than the last confirmed number, it gets dropped
If an input packet is lost in transit, the server should re-use the previous one. "Player probably kept doing what they were doing last frame" is usually way more accurate than "player did not do anything this frame".
alright
If my client packets are like 2-3 ticks ahead of the server by the time it gets there, is that too much?
Or is that a good prediction?
The optimal ahead amount depends mostly on ping. If you had a magical 1ms ping connection to some server, you would only need to be 1 frame ahead.
Also, I've been wanting to say that "tick synchronization" isn't some kind of separate, tacked-on idea. AFAIK it's a fundamental part of making multiplayer responsive and making it "fair" without lockstep.
Tick numbers are basically special-purpose sequence numbers. We use them because prediction/rollback and lag compensation need some kind mapping from input to applied tick.
A clients sends an input with a number and the server sends back an update with the same number. Ticks are intrinsically synchronized between clients because the server sends the same update to everybody. The tick numbers on two clients don't have to literally match. Maybe a client joined the session late. It's a tiny implementation detail whether you set a newly connected client's tick number to 546 because that's what the server's is or if you start the client at 0 and have the server remember to subtract 546 when it sends them a packet.
I personally use the offset method for my stuff, but it isn't required.
For example when a client connects it sends tick 1, and if the server is on tick 200, it will determine that that clients tick 1 should be applied to the servers tick 203... so it notes the offset as being +202 for the client.
Though that is a little more complicated than that, if you wrap your numbers for a ring buffer - which I do.
This is so confusing
The only reason I'm syncing my tick with the server in the first place, is literally because the client lags/freezes when alt tabbing the game and gets out of sync with the server
I still don't know if I'm on the right path
Unity is set to run in background?
Whenever you alt tab it like freezes the main thread for some reason
also if you drag the headless server application around, that also freezes the server's thread and causes the same complications
Lots of things hang it, like dragging the window, but unless its super prolonged, fixedUpdate will rush to catch up
it doesn't seem to catch up precisely
it tries to catch up
but doesn't do it accurately
Fixed has a finite number of updates it will run to catch up, so you may need to sniff out the tick count vs elapsed time to see if Unity decided to not run all the fixed updates
regardless, when fixedupdate tries to catch up, it does it all in a single update frame (I think), so like 30 packets get sent at once
I am not sure if Time.timeAsDouble keeps on trucking or not in those cases, but that would be the first thing to check
That may happen yeah, and your buffers should be able to make that work out.
Most of those updates will be too late to the server, and it will just not use them.
But if you are still keeping too time with your tick, they should still be in agreement
You're still talking about having the client synced to the server's tickrate right?
yeah
I have no idea what synced means in this context
client connects, server sends current server tick, client works out the latency and applies added ticks
You want to make sure they have consumed the same number of ticks as expected
if you are 50 ticks a second... and you hang your app for a second, you want to make sure that when it resumes it is 50 ticks later... whether or not it sends any of those missing ticks
But for the server to realize that those ticks are in the past, the client needs to be on the same tick as the server
or you have an offset, whatever mechanism you use
alright.
The two have to keep consuming at that fixed rate, no matter what.
Correct, that's not the part I'm confused about
If the app hangs for whatever reason, you need to make sure it picks up in the right place.
it's just when the client sends the 50 updates after he freezes to catch up, the server thinks all of this ticks are still relevent
and applies them into the buffer
which is why I now have them synced
so it doesn't do that anymore
Why would it think they are relevant?
It will see them all as being late
and will have already run the sim with the extrapolated values
I'm talking about the last iteration of my server, where the client starts at tick 0 no matter what
Not sure that is related to this
In the last iteration of my server model, the client would literally just send update packets, and the server would process them no matter what
if at 20 seconds in the server is applying tick 100 from the client.., at 25 seconds in it will want to be consuming tick 350
so when the 50 update packets came in at once, the server would think that ALL of those were still relevent
hopefully that clears it up
That's going to be a problem
yeah
For all of the reasons discussed here
Consume and generate ticks... at the same rate... all the time... no matter what.
I just wanted to make sure I'm doing it right
If the client stops running for whatever reason and Unity fails to run the right number of fixedupdates... you will have to determine how much it borked things up, and advance the clients tick number.
So when my client first connects to the server, the server sends him a UTC timestamped packet (of when it was sent), plus the user's session ID (irrelevent for this), and the server's tick. If 100ms passed and ticks occur every 20ms, we can predict that 5 ticks have passed since that value, right?
^ that is essentially what I do
then it does the same prediction for packets on the way to the server, so it sends them a little bit ahead of the server
As long as that gets you the right starting alignment, then sure.. that works.
alright
First step to fixing this, I would establish what Unity is doing to bork you. If it is dropping FixedUpdates you either have to advance your clients tickcount to compensate for the loss, or you will have to make a hard realignment option with the server.
You can detect that case on the client, because the server will be sending back tick results for ticks the client hasn't even run yet.
The server sending the client ticks before that client has run them should raise a flag that things are very wrong.
I think proper tick synchro should fix it
because if the server knows that it's getting late ticks, it just tells the client to resync
right?
I'm like halfway done building it, but my server does now properly detect late ticks
seems workable
Though the client really doesn't have much to do in that equation, the client already should be trying to hard adjust to keep the state buffer right.
The server in this case just needs to re-adjust its offset value
yeah Im probably going to implement a rolling average for him to adjust to
automatically
The server doesn't handle any of the offsetting on my end though, it's all on the client to get the packets in on time
is that bad?
Just a choice, if that is how you align it, then the client will need to correct yeah.
alright
I'm making online game with Photon I made the online system, but there is a mistake, we cannot see the people entering the room before us, but we can see those who enter after us, what should I do?
@quasi topaz Impossible to say without knowing what your code is, and how your components/prefabs are set up. You also have to be clear on what "see the people" means. If every player is calling PhotonNetwork.Instantiate() in OnJoinedRoom, that should be getting replicated.
are questions about mirror fine there?
any devs out there not working on a project looking for a paid gig?
or is this the wrong definition of "networking" lol
This means connectivity between game clients/servers via internet or otherwise network
Does someone know how to instantiate players at different spawnpoints? (Photon)
Has little to do with Photon. If you want to prevent players spawning at the same spawnpoint, then you should keep track of who spawned where, and pick a different spawnpoint from a list of possible positions
Either the player needs to do an overlapSphere test on the starting points to find a free one, or the master should, and then instantiate.
Hey @graceful zephyr, thanks for recording your Twitch streams. I just finished watching the most recent one. Will you be doing another stream soon? Really interested to learn about dynamic interpolation delay.
@dense hedge I'll try to do some soon again
Been very busy with work/family lately
totally understandable, looking forward to when you get the chance
@dense hedge I Will stream tomorrow (7th feb, 9PM CET)
time to start up again
can find more info on my discord, invite link here: https://hatebin.com/vkklyqldjh
(unitys bot here deletes discord invite links for some reason)
awesome! thanks
๐ thanks
Ah, smart way to share the discord links. I'm stealing that. @graceful zephyr
Hello! I just have a quick simple question. Is there a free reliable way to do multiplayer? whether it's lan or over servers, just any free way :)
I have heard of unet
from what I can tell it's free but then it says that unity multiplayer service is not
so I was wondering if you need unity multiplayer service in order to use unet
and if you do and it cannot be done for free this way, is there a different free way to do this?
Pun2 and Mirror are the most popular starting points. Free is relative when it comes to networking, since someone is going to end up hosting something, and that is never free. The only possible exception might be if you do relay through steam using Mirror.
Unet is long deprecated. MLAPI will be the closest thing. Mirror is a fork of the old Unet that has been expanded on.
yyeys I know
@jade glacier would it be free if someone hosted it on their laptop? like a lan?
Mirror would be free for that yes.
thank you so much!
Be sure to join their discord
yes sir!
MIRROR 30.5.0 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
Hi Gadget-san! Working hard i see
https://github.com/DennisCorvers/BitSerializer
Some updates!
is multiplayer free in unity?
Multiplayer is whatever you call or implement as multiplayer, so yes. If you mean a unity-provided all-purpose multiplayer library/integration, still yes, although there's currently not really an officially supported one; they recently posted about aquiring a youngster's github project as new multiplayer stack, that will be free too. If you mean hosting your server, then probably no.
Hosting a server, def not free. Can be as cheap as a few bucks per month to begin with.
But being as new you begin with local multiplayer before thinking online ๐
Streaming netcode dev at http://twitch.com/fholm tonight at 9pm CET (8h from now)
hey guys got a question
my server log is getting spammed with stuff like this
what is that?
ive been looking at it since a few days and it just doesnt stop
different ip all the time
tryed to google but people seem more clueless than anything
I'll be covering a variety of getting started topics throughout this live development series: https://trello.com/c/1X35VayU/76-streaming-live-getting-started-tutorial
PunFish is live
Teaching Mirror Networking live ๐
Looks like random DNS lookups by bots. Though on ANY... people are savage nowadays ๐
I'd say nevermind, your firewall denied them.
You might also get spammed on your ssh port, or inexisting URLs on your web root and such...
Don't bother as long as you catch them that's good sign.
Just hope it doesn't hold too much resources on your serv
for how many days ?
about 4-5 different ip every time
i was thinking of banning them with something like fail2ban but then if they start spoofing i could ban legit people
so thats a no
you could blacklist them after x attempt from same ip
gonna try to disable the logging
okay
you could also match & redirect the query to another file
to keep syslog clean
๐คทโโ๏ธ
yeah im just a noob with the logging stuff lol gonna learn how to do this things
THough regular people's browser wont query for ANy on your domain ๐ค
or client app*
those attacker if they get blocked they can spoof the ip and get other people blocked for no reasons
yeah
thats what ive read from google
thats why i dont want to ban them, they always changing ip
and its all from usa for some reasons
yeah if they somehow monitor and don't brainless spam, and they wanna make you lose your time, definitely
alright I'd just handle the logs to another file and keep going with my day as long as it doens't put your server on his knees
not yet lol
i dont have much traffic on my site as its not publicised yet so
but look at the logs
Linux ? Looks like you already have a time rotation, that's good
2MB is not scary for me
but I didn't managed dedicated servs for a loooong time
You're afraid it explodes when you go public ?
I'd wait and see at that time and move on
im gonna write down all the ip in a list they seem to come back often
if its always the same it will be an easy fix
seem to be some botnet, its often a single ip attacking 5 time a second every there and then over a period of an hour, or its multiple people attacking 5 time together a second for that multiple hours
it never goes over 5 a sec
anyway, at least i know its not dangerous for now
lol
yeah honestly, 5 times a sec every now and then is nothing
doesn't deserve sucking so much of your time
just keep an eye on it 'till the end of the week before doing anything
It's pretty normal to have bots "ping" your server in various ways
To find holes in your firewall, to bruteforce admin logins etc
yup
gg to anyone from those regions that want to use your service
or vpn users ๐
they can vpn
or ask me to unban i will for their own ip but yeah lol
too many spam from those country
but now its usa doing it ;p
out of no where
Contact the host and tell them to do something about it
Or if it's privately hosted, install one of many available software that handles these things
live at http://twitch.com/fholm now
Im using mirror and i have am using this code
public GameObject p1;
public GameObject p2;
[SerializeField] NetworkManager NM;
public void JoinGame()
{
NM.playerPrefab = p1;
NM.StartClient();
}
public void HostGame()
{
NM.playerPrefab = p2;
NM.StartHost();
}
When i host the server and get the client to join it brings a warning
Replacing existing prefab with assetId '1c32ce8f-2c14-9794-bbb2-7a5aab8fcf4f'. Old prefab 'P2Online', New prefab 'P2Online'
and the players only update for the client. if the client moves it doesnt show anything on the host screen but if the host move it updates on the clients screen to match the host screen.
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpmethod.patch?view=net-5.0 anyone know how i can get HttpMethod.Patch support in Unity, and if not, is there an alternative library i can use which supports it?
it seems to be a recent addition
Well, you can always use a UnityWebRequest instead, it even has the added advantage working in WebGL builds
doesnโt seem to support the PATCH method type either?
Yep, just use the constructor, not the static helper methods
ok yeah, sounds good! thank you, i will try : )
I don't use Mirror but are you sure you can set the playerPrefab property like that ? Aren't you supposed to call a method to grant client ownership on a gameobject to switch authority (available on a list of previously declared network objects) ??? I would check the doc for that, or they prob have a tutorial to explain how to change ownership via code.
Or even use the same prefab for host and client and check isLocalPlayer or something to handle the differences, would they be tiny.
https://github.com/DennisCorvers/BitSerializer
Another update. Unity and Net binaries are available under Releases.
What is p1? A prefab or a GO already in the scene?
U need to use SpawnPlayerForConnection to set it as the client's player object
If its a prefab and not instantiated yet, then it needs to be instantiated first, server side
If its already network spawned, then u use SetAuthority
Is it normal for a website, like Microsoft to block requests after you send enough requests for the time?
I made a Fortnite-style live event countdown that gets the time from www.microsoft.com when the project starts, then uses it as a base to count down to the event. After enough time, it stopped getting the time, but then worked again once I switched to www.google.com.
Yeah sure if you spam them they gonna blacklist your IP
Why don't you get the time from the system ?
Guys, I'm making a carrom game multiplayer with Photon, I'm syncing player positions and velocities using Photonnegtwork.raiseevent. It is working fine, but issues happening when syncing positions if my network is unstable. Guys, is there a way that we can sync the key position, something like holding raiseevent and raise it once the network is stable?
Does a Peer to peer game still require a central server to connect/find each player?
no
if you want to save friends or stuff online thought you would need a server
but connecting and finding player in same lobby is possible, matchmaking
P2P is a poor term really, and is problematic when talking about MP games.
P2P typically implies clients all interconnecting directly to one another, which is super rare in gaming. There is almost always a server. It just may be a relay server, or that server might be a client listen server (a player that is acting as the server).
So when people say P2P they really typically mean either mean that a player is acting as the server, or all players are connected via a relay server.
In which case, be sure to indicate which you mean.
@quaint hull
2d game that sends json data between each user
how though? How are they connected?
Thats my question. Wouldn't I need a relay server to determine if they are online and connect them
You need a server of some kind to get started yes.
yeah that was my question thx
Although json isn't resource intensive compared to tcp so it shouldn't really be an issue
With relay like Photon Pun, you start by connecting to the master server, and then that directs you to a game relay server. For mirror you would need a matchmaking server as well, and then a server to handle punchthrough if you want a player to serve
no idea what you are using json for or why, but that is a separate conversation
I don't need to send tcp packets, text works just fine
Too much to unpack here, so I won't get into that.
I would start by doing a tutorial for Mirror and Pun2... unless your game is completely turn based, then look into a cloud service of some kind.
Don't start by trying to make your game. Your first networking attempts will be a complete mess and likely failures. Start with tutorials and basic tests to get your head around the options and concepts.
Dude i'm making an airport traffic controller game where players can send aircraft to each other. That doesn't need tcp/udp packets because its not a lot of constant data
Simple GET and POST requests to the server works fine but I was wondering if it was possible serverless (aka P2P).
But what you just told me is that I need a server to connect the players together in the first place anyway
If you are doing this as a web application like that, totally different animal.
Last time I checked GET and POST requests are in the networking category so...
That is more of a cloud scenerio, do it like its a webpage.
I'm just going to use Python backend on a webserver, because P2P will require a server anyway
Not typically the kind of networking convo here, usually this is more about realtime state synchronization. P2P is still not the right convo in that case.
But sounds like you have some ideas you want to try, so go for it.
I understand what u are saying but... P2P and webservers still count in the networking category
Sure. I am not the right person to answer. What you are doing is a bit out of the usual for this channel. I'll just skip out of this convo.
Your good tho, you've already answered my question about P2P
Get post.. rest?
U use unitywebrequest for that
Technically thats still networking i guess. Those stuff are under unityengine.networking namespace after all
@grim violet , for example, if I just struck a coin, just at that moment I got an internet connection issue, I need to cache the position, right?
so for that any method available?
I've never had to make a network architecture for a turn based card game before but I will Soonโข๏ธ
My first thought was REST API, full server authority, simulated games, sort of setup. Are there better/different ways?
"Simulated games" ?
Well, have the server simulate the game before authorising a move
I am not sure if I used the right terminology
With no-sim games like those
You can input the action on the client and server
And rollback the client if the server says so
Forward the message to the other client if the server "accepts" it
But no idea how you want to do that through a rest api
Websockets, or?
You need full duplex
Hm okay. I was just thinking the clients send messages to the server and then check every x tick for updates
Seeing as it's turn based events visuals and whatnot won't have to happen exactly simultaneously on both ends right?
I've done turn based on a rest-api before... It's a good enough approach
Has its pros and cons
If you are confident and experienced on the backend stack you plan to use, it's a good approach for slow paced turn based...
periodic polling is OK-ish, but if you could have duplex comm to notify of changes would be even better.,
Nope they don't. And neither does that happen in any multiplayer game (maybe there are exceptions)
My experience with net sockets just seem to indicate that scaling is much more expensive computationally. But maybe I'm just wrong there?
And are sockets similarly platform agnostic?
I think the .Net Sockets are platform agnostic, but I'm not 100% sure on that one
Ah okay. I'm most familiar with C# so would be nice to use that. I could probably also use node.js if I wanted to
There's also the option for IOCP with .Net Sockets, but I've never tried that
That's apparently for "highly-scalable" TCP servers according to Microsoft
No clue how well that works with Unity and IL2CPP
Right
But that's for the server side, and that wouldn't need to be Unity anyway
I would look into setting up a websocket in Unity. There's probably people who did that before
If you want to do that from scratch look into the websocket specification
It uses 'normal' sockets with a modified protocol
Cross-platform and plenty of choice of ways to solve your problem
So n players queue up for a game. They have a socket established with a server.
The server now tries to match players.
It makes a match and two players are notified of this. The clients transition to some sort of battle scene while sending a token to a different server program that sets up the battle and manages the session.
The server already knows what decks the players use as they queued up with those decks.
The clients are given data equivalent to a starting hand.
The game starts.
Does that sound right?
.net sockets are platform agnostic though
Does this mean that, when using the .Net Sockets and IL2CPP, this works for every supported platform?
Yes
I don't think IL2CPP changes anything about the actual .NET implementation of sockets
I've made both windows and linux clients with .NET sockets, they use same codebase
On windows it'll use winsock most likely, but that's a lower layer you don't have to worry about
I know, but I'm saying that it has to change the implementation somewhere
To not use WinSock
Why would that matter
The low level implementation is different, but you don't use that directly anyway
Because if it didn't, it would only work on platforms that use or support winsock
Which is the entire point of the question
I have a server running on linux, the clients are linux and windows. Both clients can connect perfectly fine
Only thing that really matters is what socket protocol you use, whether that is TCP or UDP, it doesn't matter what underlying socket library is being used because it'll support both protocols
If I write my own C++ socket implementation using winsock and use that in Unity
Pretty sure it's not going to work on most platforms, even though it is tcp or udp
If you insist on writing it in C++ then yes, you're on your own
You intend on using UDP?
Depends on the game
Consider this library it has reliable UDP https://github.com/nxrighthere/ENet-CSharp
I know of ENet
Just wondering how far that platform support stretches
ENet supports all 3 major platforms
Yes, that's what it says on GitHub
But that doesn't answer the question how far that exactly stretches
Well define exactly
If you open the list of possible platforms to build for in Unity
It supports windows/linux/macos and that's it
Expected as much
No mobile as far I know
I can't say with certainty but I think iOS and android support unix sockets
They are both Unix based right?
Yes
So it would stand to reason
At least I assume they both are unix based ๐
I could see iOS have some Apple fuckery but other than that
The "problem" arises from using .Net Sockets on a high-traffic server
I doubt consoles do sockets very different
It's no problem at all to use them for a client
I wouldn't care about consoles for this particular usecase
Probably .net itself isn't the problem, more likely how you allocate resources
Though if I need to support n card games at a time then what would be a good scalable solution?
The .Net Socket implementation isn't particularly good though....
At least, not the one we can use in Unity
@dim merlin Again, just use .Net
Mkay
Well trying to support many platforms is like opening a can of worms
OmniOwl is right though, server doesn't even have to be C#
There shouldn't be a shred of unity in the server client
That's where you actually have more choice
That's why I asked for agnostic tech
Well, tell me what a good, high performance cross platform language is
Which is easy to work with as well
Unity is unity. That will be the client side so I'm settled there
You can also use C++ then ยฏ_(ใ)_/ยฏ
C# is just a whole lot more programmer friendly
Sounds like music to me
https://github.com/DennisCorvers/ByteStream
Another update
I need some help, I made a raycast gun script and everything works fine, except that I still need to make it work with PUN 2. What I have so far is just the base code, I haven't really added any networking to it, and I would like guidance in doing so since I have no idea what I'm doing; Here's the script;
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
well this is definently an active server
should start by doing the tutorials of pun2 to test out the stuff
there is alot to it
i have no errors, players just cant see other player names & only see DEFAULT USERNAME. its like the first player that joins has a name that works and the second player can see it, but the first player cant see the second player's name and all it says is "DEFAULT USERNAME"
halp me
sorry networking is a really specific area that not every specialises in
i don't have a clue about it
oh ok
im not sure if my problem is even networking cuz its just not diplaying stuff properly
do you know any other places where i can get help?
there might be other discords and forums that are specifically for networking but not anything specific
well you are sending a rpc in update
that mean its gonna be sent 60 time a second, very bad
nickname should be set before connecting
Hey qick question so ive been using photon pun 2 in my game, I can load people into the main menu lobby perfectly fine but when i launch the game and both players are instantiated into the scene they can't see eachother anyone know why?
Okay thanks i'll check it out and see
how?
before joining a room i mean
would i have to recode it all?
no
Is there an easy way to create/apply an input to a simulation using the "new" input system?
Or does it still boil down to a bunch of if-statements
I am new to Networking and PUN and i am facing a problem using RPCs. I have game in which you and the opponent throw discs towards middle to a target and when disc counts of both players are 0 the game calculates the scores and a game over UI gets activated. I cannot seem to successfully set player1Score and player2Score variables on my Game Manager script. I am trying to use an RPC method to set these variables from its respective Player Manager scripts and i have tried all the RpcTargets with no advancement. If somebody could help me i would be very happy.
Edit: it is photon2
can someone explain to me why this only works for the master client? im using photon pun 2 btw
Anyone try one of the MMO systems?
So when my client presses E to use an object and raycasts to it (like pressing E to enter a car), should the server also "press E" and raycast to it, to see if the user can actually enter the car
or should the server just check if the player is in the proximity of the car when the player requests to enter it, if so, let him get in?
@slow monolith id take the second
a little delay before entering the car would make sense
i think pretty much all games to it that way
i am not sure how you are going to do it
but id just design the system so the remote character is controlled by my keyboard and nothing else
so it wouldnt be like client sending a "vehicle embark request"
it would be a natural result of servers character looking at right direction amd pressing E the right time
Anything you can avoid predicting, I would.
cleaning up missed predictions is always a pain. if it doesn't need immediate feedback, leave it fully server auth without prediction.
You can hint to interactions, like trigger an animation or something that indicates your click registered.
let me ask something i was wondering,
are there networking approaches that involve sending states sparsely?
If my game simulation is 50hz or 50 ticks per second, is it a good idea to be sending 1 out of 5 ticks to save bandwidth?
I did something like that before with my previous approach, but it gets complicated to produce what happened between the synced frames
Im talking about a fixed timestep tick based system, something you can run predictions on
Most systems do some form of delta check, and only send updates when things change. But it is not super basic (unless you are using a reliable transport) because you had to factor in the need to resend and such.
You can send Every X as well though sure, if you design for that.
Typically for that you work with multiples
so if you sim at 60hz, you might have a net rate of 20hz, by sending every third simulation tick.
You can do full prediction and also predict getting into the car for sure
Worst case if the server denied your prediction, you find yourself back standing in the street.
I'm trying to send status packets only when the current status class is different from the previous. The networking code that checks this is in a loop attached to a separate thread. Problem is that it is TOO fast! I keep calling the method for sending packets, even when the status has not changed. Is there a better approach?
I'm posting the code...
I'm using UdpClient.SendAsync() as the send method...
Thanks in advance for all the help! : D
guys
is there any way to multiplayer
for free
without using any paid servers
i heard peer2peer might do
Well, you could use a VPN like Hamachi
your packet sending depends on isEqual but you've set isEqual to be false when the status hasnt been received? So the time interval between sending a packet and receiving a packet is the delay that causes the packet spam right? Shouldn't it assume that the isEqual is always true unless a status has been received, then it can evaluate whether it's true or false?
It's not about checking if the received status is equal to the previous, it should check if the playing character status is different, and then it should send the packet with the new status... For now i solved the problem by putting a Thread.Sleep(16) for every iteration in the loop.
Hello is there anyone who can help me in synchronization of variables,object.setactive synchronization in photon pun untiy?I followed photon pun docs byt I didn't get it.
Let me make this clear.
I aactually achieved synchronization but when I tried to synchronization varaiable of other scripts in another script it was not working.I am using OnPhotonSerializeView.
show ur code
I guess that's a no ๐
Does anyone have a video that teaches how to do multiplayer with no background knowledge of multiplayer
I am doing the gamedev .tv course on Unity multiplayer with Mirror. It is rather high tempo but you can follow along pretty easily and goes through the basics. Not very detailed into how multiplayer works but much of that is hidden behind the framework anyway, can recommend @dusky wedge (I got it through a humble bundle so pretty cheap)
@rare grove you can use Mirror with the steamworks integration. That way anyone can host and clients can connect without having tow orry about NAT punchthrough or port forwarding issues. Only available on PC (the steamworks part that is) afaik
@dusky wedge basic background knowledge is:
you have two scenes in two computers
you want to keep these two scenes as closely synced as possible
and for that, you send some data back and forward
and keep that data as light as possible
thats the common thing for all mp projects
I would start with doing the Mirror and Pun2 tutorials. Those should at least get your head around the idea of asynchronous state transfer. But know as you are learning them that you are NOT learning good networking practices, you are just getting familiar with the difficulties of trying to synchronize states over a latent/lossy connection. @dusky wedge
Your goal start is just to even get enough of a concept of the difficulties to be able to start asking the right questions.
@rare grove yes, you can do multiplayer without purchasing server infrastructure and no, it doesn't have to be peer to peer. One of the players acting as host and synchronizing everyone is still client server, not peer to peer. The correct avenue to go down depends entirely on your games needs. As mentioned above, if you go user as a host, you may have NAT concerns and just general user understanding of networking pains unless a lib helps with that. Like steamworks. This is how it was done alot in the old days, but, kids these days won't want to deal with I suspect. "Enter server ip!?! Wtf Is that" :b If you have a ton of people connecting, this can also not work well because generally end user pcs are not as powerful as dedicated servers. I personally like this model because it's cheap and I'm technical. I also like this model because games that do this usually allow me to run my own server for my friends. Totally depends on the game. As others have mentioned, mirror is a good place to get started, but be prepared. You'll be taking on a great challenge. Tell us more about your game and maybe we can give more direction.
@dusky wedge, multiplayer basics comes down to computer networking basics. Depending on where you are in your programming journey, we can offer different appropriate materials. Im a big fan of learning the concepts separate of gaming and then applying to gaming with use of a library and engine. Networking can take a bit to wrap your head around. But start with basic socket programming in c# (I'm guessing 5hats what you know because this is a unity forumn). The documentation on the system.net namespace is pretty good, but, there is an older book on the subject https://www.amazon.com/dp/0124660517/ref=cm_sw_r_cp_apa_fabc_2SHWYC6QCVZMV3M4TGPJ
Unfortunately I am not aware of any video materials.
I know what was asked for is multiplayer game programming, but, I believe anyone without a bit of computer networking knowledge will be very confused.
tysm
sounds great to hear
since its dependent on user we cant make the host calculate every single thing i assume
and client also have to do some of the calculations
Hello, im trying to learn how to use Mirror and discovered the Network Discovery component. So far, that component works locally on my network but i would like it to work globally (wan) to search for other servers in the internet.
Is there a way to do so?
Or are there any sources explaining how to search for a server globally?
hi all
I finally was able to create my own custom networking protocol, and after lots of tries and fixes, IT WORKS PERFECTLY! I'm so happy!
If anyone would like some tips on how to create their own networking protocol for their game, i'll be happy to share some๐
does anyone know why i can shoot a particle with a collider through someone on the machine getting shot at, but the other it shows it getting hit, i know it has to do with like adding a rpc or something somewhere or maybe its external i am not sure though, this is photon pun
@rich narwhal You could try sending to server the collision details, the server checks if the collision really happened, by looking at updated player's stored positions. And if the collision really happened, the server sends a message to all clients, notifying of the collision.
that would be like if photonview.ismine correct
i just started networking like 3 days ago
I don't use photon, i created my own networking solution using sockets
oh ok
How hard is it to setup a multiplayer fps/ rpg? What is required in terms of server etc
Am i going to write the networking myself or does any asset make this for me?
depend of how many feature your game have, there is many network library already and you can make your own too but that will add alot of time to the making
if you want to save data online you need ur own server (or use a service like steam or whatever else there is, not sure how they work i make my own)
some fps are just shooting game with no record so it all depend on what kind of game you making
@zinc hull
it is hard
and fun
i personally use python non blocking sockets on python, and c# sockets in client side, with a custom packet structure.
It'll be at least twice as much work as an equivalent singleplayer mode, even with a HLAPI. More, if you're new to gamedev and/or network programming (you are both). Some features will take 3-4 times longer to create. You'll have to fix bugs that can take hours/weeks, which simply wouldn't exist in singleplayer. Everything you create must be funneled down a narrow tube, with little wiggle room in terms of architecture. Planning on using dedicated servers? Make that at least three times as much work. Can players run their own dedicated servers? If not, add a mountain of extra work for the server operation. Oh, does that game have PvP? Don't forget to add another multiplication to that workload for anti-cheat, and server-authoritative design.
This is all a multiplier to the enormous workload that even a small RPG can be.
Has anyone ever had an issue with Mirror networking where calling NetworkServer.Unspawn within the OnStopServer function causes the object to still get destroyed?
Ah, discord links are bant. But yeah, Mirror has their own discord.
Absolutely full of people who use it every day
oh nice, must have missed that. Thanks for the heads up!
@rare grove correct. Not everything needs networked, only the things that do for your game. For example, you don't need to hear their music or menu sounds. But you might want to sync footsteps
can u tell me exactly how multiplayer works?
is it usually just sends a simple data constantly?
or more complicated than that
look up gdc networking and you can dive headfirst
@rare grove you just try to send as little info as possible to keep all players scenes in sync
got it
if you were doing a chess game for example, with only sending players inputs back and forward every turn, you can keep the scenes in sync @rare grove
input would be like
what pawn will move, where it will move
in chess?
yes
yea
but
also one more thing
you generally wanna have one of the players/devices or server have authority on everything
authority can be split among players and stuff
.
but if you wanna keep it simple for now, you can think like this:
server instance is where the game runs,
clients are just sending inputs and trying to keep their scenes in sync with server depending on the data they recieve from server
@rare grove
yes
client sends input, host calculates it and sends output to all clients, clients do the rest based on the output
yes
got it
but that sort of thing will result in input delay proportional to clients latency to server
so if i set a player as a host instead of a server
so you explore more options if thats what you need
if you use mirror for example, you can host just like you host a minecraft server
like multiplayer without using a seperate server
your lan friends can join,
if you are on a static ip i think everyone can join with that ip
or you make a hamachi room
i dont know low levels of networking much
but i think that answers the question
TCP/UDP punchthrough and UPNP are also two options
Last option is port forwarding manually
Session Traversal Utilities for NAT (STUN) is a standardized set of methods, including a network protocol, for traversal of network address translator (NAT) gateways in applications of real-time voice, video, messaging, and other interactive communications.
STUN is a tool used by other protocols, such as Interactive Connectivity Establishment (I...
Okay! Unity has a multiplayer template that i can learn a little from?
If you start making a 2D mmorpg in unity 2020/1.
Which of all networking solutions available would you use? (and why)?
Mirror looks like the best option by far, but it leaves out so good updates for 2D cause is locked in LTS.
You shouldn't choose a networking solution based on if it can do 2D or 3D because all can do both. The more specific you want a library to be, the less flexible it'll be as well
I would agree with you if I were working on a library, but when you are working on an specific product, having a "flexible" solution usually takes you to problems like poor performance, bloated code, etc.
If I know I want to make a topdown 2D rpg, I dont care if the networking solution can handle physics or not. Even better if it does not.
Same goes for the "mmo" part, not all solutions works for a large number of users present at the same time.
Depends of many things, is the game real time? turn based? do you care about cheater?
Plans change depending of library, some are free but limited, other you gotta pay by concurrent connections
Now handling multiple people wont only depends of your library, but alot more things
With flexible I mean not everything decided for you already so you have to do more work yourself, it doesn't mean the library is bloat (it actually is more likely to be very lightweight)
starting from scratch is prone to error if you just beginning, while libraries have years of experience and multiple developper behind
if you think you can handle that heat, go for it ๐
but just that is a project by itself
It is and I would go so far to say that if you have to ask what solution to use that you probably have to reconsider and first do some more research to get a better idea of what is out there and what the best solution is for your project
Good question , to answer them all in a simple fashion , lets say I want to make a Tibia online clone.
i dont know what that game is but seem to be real time fighting
I did some research, but Unity is at a weird moment for Multiplayer.
With UNet deprecated , and everything else very green, is hard to say what third party solution is the ideal.
Don't ever rely on unity multiplayer, they have a terrible trackrecord of multiplayer implementations
using something like photon cloud would work but cheater will be happy, since its client authority
if you want a safe anti cheat game you need server authority over real time, so either Mirror or photon server (or any other library out there, i just name those cause they are common)
I have to say, also... that my last time working on a "simple" multiplayer project was back in Unity 4.6
I was away from this topic far too long to just know "what is working" now.
On my everyday work , I'm working on a DOTS+NETCODE , but this doesnt apply at all for what I want to do.
If you want a free library that is also scale-able I can only think of Mirror and ENet. There are many others but if it were for me to decide I pick either of these two
Yeah , not good for a mmo.
Mirror is locked in 2019 LTS, which doesnt work for me, because I want to use the new features avaiable in 2020/1.
While I was doing some research I found DarkRift got a new version , DarkRift 2, did someone use that?
I haven't
depend what kind of game really, im making a mmo with photon cloud, but its turn based
But what new features are you talking about because I fail to see why a networking library should be so entangled with the latest unity versions
Tilemaps, 2D ShaderGraph, 2D Lights, Visual Effects Graph, and some other that AFAIK , are not available in the LTS version.
(Tilemaps upgrades*)
what do you mean 2d shadergraph
Thats why I want to use Unity 2020/1.
Mirror , since is built on top of the old Unet, is locked in on 2019.
Fair enough, but that's kind of what I meant with lack of flexibility. You're going to get stuck on things and not being able to work around them easily
2019 got all this but i thought visual effects graph was only for hdrp?
the 2D renderer for URP ShaderGraph compatible.
maybe urp
URP
i use shadergraph in 2019 with 2d and lwrp
In my opinion a networking library shouldn't deal with any game structures itself, but rather only with connection handling and data transfering
and got new 2d lights
all this is there since 2018
i didnt know vfx graph work with lwrp... maybe something im missing, tryed to use it myself and it didnt work
ah i remember its cause my game is webghell, doesnt support it
;p
:P, Web is always the special case
does anyone know why on one machine a particle collides but not the other?(PUN)
So I'd like some opinions on this!
I looked at Mirror today to hopefully be my network layer for a multiplayer turn-based card game. But I learned today (according to the official discord at least) that in order to make that work, it would essentially have to be P2P rather than server authoritative as Mirror would have to run through Unity on both ends.
This is obviously not desirable as that would cause some legal issues (I think? There was that server hosting site once right?) as well as massive slowdowns because Unity would have to be the middleman there for server interactions. I was told to do a custom socket setup, because otherwise there wasn't really an option like what I was looking for.
So I set out to find some sort of starting point, but obviously that's not so easy. I stumbled over these two examples for an async client and server based setup and was wondering if that would be a good place to start?
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-client-socket-example
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-server-socket-example
If not, is there some super amazing library/framework I just don't know of and should probably use instead? Is PUN usable for my usecase and potentially easier? It could be that it's fine for an initial setup at least, but then a custom solution later.
SpatialOS was the service that got in legal trouble. Hosting Unity servers for your own game should be fine, which IIRC was specifically outlined in one of the blog posts that came out of that.
Right okay. I couldn't quite remember what the outcome was of that
spatialos is used by unreal engine i think
SpatialOS is just a server hosting platform I believe
but its owned by epic games or unreal or something
Didn't they just go into a partnership after the fact?
I don't think they sold to Epic did they?
If they did I missed that
Epic did jump in to do stuff while the thing was going down, so Epic has in the headlines at the time
Yeah I remember that
It was seen as a little too perfect timing
At the time
SpatialOS knew it was coming, were doing deals with Epic in the back
They come out antagonising unity
Kinda like Epic's case against Apple
Apple has become too powerful and rich of a company
Most mega corps today should fragment
Split up
But anyway
That's off topic
I need help with this #archived-networking message
Q_Q
turn based card game could be made with about any solution really
My initial thought was REST API, but someone said I would need full duplex to make it work properly
full duplex?
well again it depend
but yeah most multiplayer stuff require bi communication
;p
unless u playing alone
No it would be a card playing game with people against people
hm
ive played huge card game like Tyrant which had tons of player it was using rest api too
I want the server to have full authority, essentially simulate the game so that when a client makes a request the server can know whether or not it's a legal request.
you could play the entire game on client side then send the whole played game to server and server calculate it all
it depend of how much effort you gonna put in
thts why you use a database on server and dont trust client change but server change
The problem I guess is that without sockets, the client has to ping the api all the time for changes, but maybe that isn't an issue?
if client sent "hey i did this then this" then server cehck against db if its possible or not
you could do it all the time for change, on every small change
or keep them in a pool then send the whole thing
its up to you really
rest api can be load balanced easily if you are hosted in a managed cloud
hm
So I need to set up something like sockets, but not really.
When a client connects it has to ping the API every X ticks for updates
Or I guess I could await..
you want authoritative server then
sending tons of tick every second
at least thats what you seem to be talking about
but its not necessary for at urn based game
its more for real time stuff
Well yeah. I know it has to be authoritative server for this setup. It can't be any different than that for what I need. I'm just trying to think about the logistics of using REST for it
rest api can be authoritative too
its just slower movement
you dont have to ping it every X second or whatever
you dont even have to check if its online
you just send your change you want to do on the client
server take care of the rest
the logic can hard to get thought
before making my game i thought about it for a couple weeks/months to make my head around it
but it work
Well look at it this way:
- Player 1 asks the server to make a move.
- Server receives the move and sends a code back whether this is legal or not. (let's assume it's okay this time)
- Player 1 is authorized to put down a card.
How do I notify Player 2? Player 2 must be pinging the server every few ticks to see what happened last, so it can be shown on their screen too right?
just think about it, most Actions trading website use rest api, you got a client with all the data that you can buy and sell actions, can you cheat? nope
;p
Look at my hypothetical. Am I correct in assuming that I'd need Player 2 in this case to ping the API for updates all the time?
Because without sockets, there is no other way to do it right?
player 1 and 2 send whatever move they do, they can cheat with each other client, but once the server will recognize whos the winner, he can obviously find out if a player cheated by comparing values with database and processing the fight between those 2
thats peer 2 peer
This is turn based though
