#archived-networking

1 messages · Page 91 of 1

slow monolith
#

You probably already told me how to do it, but I have a brain the size of a peanut

gleaming prawn
#

Sorry, I said the same things many times. Same for fholm:

  • you need data from server stored in separate places (not directly on transform)
  • data from server replaces the client data (not on transform) for the same tick (original@one was predicted data)
  • then with server replaced position for tick X, you resimulate frames X + 1 and up all the all to current time in client.
    THEN, just after you have all this right, you interpolate (for clock aliasing)
#

And physx determinism is not really relevant here

#

Unless you were sending server data at very long intervals

slow monolith
#

I hate to sound like an idiot, but I've already done everything you've said, including replacing the position for tick X, and then re-simulating the frames up to the current time

#

My resimulations are done in a different scene, and then the main scene just grabs the new current time position from that

#

The literal only thing I'm stuck on, is just getting from the old position, to the new re-conciliated position (after the resimulation occurs), smoothly

#

Just clientside. No serverside involved for this problem

#

As of right now, I have it setup, so I have two gameobjects. One LocalPlayer, which is the main player and LocalPlayerResim.

The second the resimulation completes, LocalPlayerResim gets snapped to the new position and moves with the controls, and LocalPlayer loses control, then lerps to it, but this causes jitter

#

Watching fholm's stream right now about snapshot interpolation. Hopefully that's what I need.

gleaming prawn
#

wait, reading

#

I am confused with LcoalPlayer and LocalPlayer resim

#

This is not the split I mentioned

#

the split is:

  • LocalPlayerSimulation (this is both server + resim data on top)
  • LocalPlayerVIEW (this is what you see)
#

And the operation is:

  • Server data replaces/snaps over LocalPlayerSimulation
  • re-simulation of buffered input modifies LocalPlayerSImulation
  • new input advances prediction operating over LocalPlayerSImulation
    THEN:
  • LocalPlayerView copies (or interpolates) data from LocalPlayerSimulation
slow monolith
#

yesssssssss

#

this is what I want

gleaming prawn
#

This is what you need

slow monolith
#

That's essentially the setup I have, I just worded it weirdly

gleaming prawn
#

assuming you have a synchronized tick system (which I said many times - I assume you have)

slow monolith
#

Yes. I do

gleaming prawn
#

You may have an issue in many many places

#

And the suspition always starts with the tick system

rigid raven
#

Anyone have some tips on performing a file transfer through LLAPI?
considering just using TCP and sending the file to the client in a bunch of packets with a header
question is what to put in that header
ill be sending textures, a json file and some audio files. all files are up to about a mb in size

slow monolith
#

So to confirm, LocalPlayerView, does not have any movement properties at all? It just lerps to LocalPlayerSimulation?

rigid raven
gleaming prawn
#

Let me give an example:

  • you have data from server for tick 42, and you predict locally up to tick 45
  • when server data arrives for 43 or 44, you predict again 45 (and also nect on the new clock time)
  • LOG the DIFFS of the prediction before and what was received from server
#

THey should be MINIMAL or nothing

#

(test on a STATIC scene, no moving boxes at first - to simplify - just your character moving around on input)

#

On the same tick, predicted data AND server confirmed data should be SAME if running both on same machine even

slow monolith
#

They'll still be the same even on physx's non deterministic system?

gleaming prawn
#

Before you go into VIEW interpolation, make sure your tick based sim behaves like I said above

#

They will if the same conditions were used at start on the SAME platform

rigid raven
#

@slow monolith prediction will be mostly similar but probably not 100%

gleaming prawn
#

Even if they drift, they will NOT drift by A LOT over 2 or 3 ticks

slow monolith
#

Alright

gleaming prawn
#

This is the role of server confirmations + reconciliations, to fix for these small discrepancies

slow monolith
#

Correct, that is exactly what im working on

gleaming prawn
#

And also to fix when your movement is affected by things done by others, etc

#

Start by making sure the tick system is sound wit these DIFFs

slow monolith
#

Tick system is fine as far as I can tell. So wait, LocalPlayer and LocalPlayerReSim both run inside the same exact scene?

#

I'm 99% sure of what you're talking about, just want to confirm before I go to bed

gleaming prawn
#

yes

slow monolith
#

And then LocalPlayerView doesn't handle ANY movements right?

#

It's only job is to lerp smoothly?

gleaming prawn
#

you only need ONE physics scene for the client

#

yes

slow monolith
#

Ok that is where I'm at

#

getting it to lerp properly

gleaming prawn
#

and this view interpolation is OPTIONAL

#

It's just for clock aliasing

#

So IF you are going for that, you need to store 2 positions from the simulated ticks:

  • current last tick
  • previous tick immediately before
  • (and) the partial clock not complete for next fixed network update
#

This is NOT necessary depending on how you make your local client clock move ahead

#

There are a few different techniques

slow monolith
#

Say I didn't do this, would jitter be more obvious?

gleaming prawn
#

They depend on how you advance the local client clock

#

Have you logged the tick diffs?

slow monolith
#

one sec

slow monolith
#

Yeah, if I'm doing this right, the tick diff is off by like a thousandth of a decimal

#

so literally nothing

#

Its 1 AM and I'm really slow, just trying to finish this problem before I go to bed

#

So when the LocalPlayerReSim object gets snapped to the updated resimulated position, and then continues moving with player input, couldn't I just use unity's built-in lerp functions to lerp the LocalPlayerView to it?

#

Because LocalPlayerReSim is an invisible object right?

#

You also told me that the LocalPlayerView lerp is optional. So if I didn't do it, the player would obviously see the microteleport after the re-sim happens right? At least that's what I saw when I tested it

gleaming prawn
#

ye

#

you can just try a lerp, but just a tiny bit

#

as you want responsiveness

slow monolith
#

That's exactly what I was looking for, Thanks

slow monolith
#

Would smoothdamp work better? Or should I stick with lerp?

slow monolith
#

And lastly, this system should pair well with cars using unity's wheel colliders, right?

hasty sinew
#

Heya
I am using Mirror for my networking.
I was wondering how I could Network an Animation component.
Not to be confused with the Animator component which has a pairing NetworkAnimator component when using with Mirror.
Let me know, thanks!

hasty sinew
#

== == ==

#

I was wondering if someone could help me? I am a bit stuck with some Mirror networking stuff. I have this system where the player can click on an object (the object has the script) and then drag it around by dragging their mouse around, then when the let go of the mouse button, it stops being dragged and re-enables physics.

#

It worked really well for the person moving it all as long as they were the host.

#

But, I struggled getting it to work with clients.

#

I managed to get it to work for them but it wouldn't show.

#

I had a look at some Authority stuff but gave up because I couldn't figure it out.

#

So I resorted to using [Command] and [ClientRpc]

#

So I would trigger a [Command] when the LMB was clicked and that [Command] would trigger a [ClientRpc] which would do what the OnMouseDown() originally did.

#

However, I am at a dead end.

#

None of it is working.

#

It only works when the client spawns in the object using a little system I made.

#

But that's not how it should be.

#

There are multiple objects that are made before runtime that have the script on them and don't work.

#

I have uploaded my code: [REDACTED READ BELOW]

#

This is a call of help! Please somebody save me!

#

I sent the wrong paste link!

spark void
#

Any coders out there know a thing or two about netcode in Unity? Looking to make a very basic, lightweight VRChat type social game (non-VR).

We'd need to synchronize things like players existing in different scenes, avatars, inventories, text chat, and random matchmaking. Prob wayyyyy harder than it seems.

muted garden
#
   Vector2 movement;
     Vector2 mousePos;
    public Rigidbody2D rb;
    private Camera cam;
    public Animator animator;
    public float moveSpeed;
    #region Client
    [ClientCallback]
    public override void OnStartAuthority()
    {
        cam = Camera.main; 
    }

    [ClientCallback]
    private void FixedUpdate()
    {
        if(!hasAuthority) { return; }

        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);

        Vector2 lookDir = mousePos - rb.position;
        float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
        rb.rotation = angle;
    }

    [ClientCallback]
    private void Update()
    {
        if (!hasAuthority) { return; }
        mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");  
    }
    private IEnumerator Punches()
    {
        yield return new WaitForSeconds(0.27f);
        animator.SetBool("Left Punch", false);
        animator.SetBool("Right Punch", false);
    }```

My player is not see each ***moving *** (they see when they spawn in the world) it was working before then i added the ```cs
    private Camera cam;

Then it stop working

#

(using mirror)

slow monolith
#

@spark void I'm writing authoritative netcode from scratch

#

I might be able to answer a few questions, still figuring mostly everything out though

#

If it's not a competitive game, you probably don't need authoritative netcode, which simplifies things a lot more.

spark void
#

It's not competitive in any way. Simple stuff.

-Players will be able to explore all scenes seperately, but their movements and actions will be synchronized.
-Players will be able to chat with each other with text.
-Players will be able to manipulate rigidbody objects and store some items in a small inventory that can be summoned forth for interaction, e.g. they find a basketball in Scene1, they take it, then bring it out in Scene2 and throw it.

The tricky part ...
-The player will never see a server menu. All online elements will run in the background.
-The game will constantly check if another player has connected yet. If not, it will seek players currently in-game and match them silently.(ALTERNATELY: If player-to-player seems impractical, players could connect to a single dedicated server that I'd host myself.)

slow monolith
#

If you need to synchronize rigidbodies, like being able to fling them over a network

#

then you'll need an authoritative server model

#

How I do mine is, literally have a server running a unity instance

#

so it knows what rigidbodies and physics are, etc

#

The clients themselves probably don't need to be authoritative. What I mean by that is, they tell the server their position, and the server doesn't do any checking to make sure it's correct

#

GTA doesn't use authoritative networking for their multiplayer, hence why there's so many hackers that can fly, spawn in money, kill everyone at once, etc

#

So its really up to you

#

If you do choose to make your clients authoritative, then you'll also have to make them snap back to a correct position (If they were at a wrong position, different than the server) smoothly, without causing jitter

#

that is where I am with my project as of right now.

spark void
#

Makes sense. Movement should be simple to synch, as it'll be grid-based and not smooth. If it would simplify things greatly, I could remove rigidbodies entirely and keep things static or animated.

slow monolith
#

Only the server should really have rigidbodies

#

when a rigidbody moves on the server, the clients will just interpolate that gameobject

#

so it looks as if it has physics properties on the clientside (which it doesn't)

muted garden
#
  Vector2 movement;
     Vector2 mousePos;
    public Rigidbody2D rb;
    private Camera cam;
    public Animator animator;
    public float moveSpeed;

    public override void OnStartAuthority()
    {
        cam = Camera.main;  
    }

    [ClientCallback]
    private void FixedUpdate()
    {
        if(!hasAuthority) { return; }

        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
        Vector2 lookDir = mousePos - rb.position;
        float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
        rb.rotation = angle;
    }

   [ClientCallback]
    private void Update()
    {
        if (!hasAuthority) { return; }

        mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");

   
    }

    private IEnumerator Punches()
    {
        yield return new WaitForSeconds(0.27f);
        animator.SetBool("Left Punch", false);
        animator.SetBool("Right Punch", false);
    }```
#

Only the player that host can be seen MOVING on other clients
Other client can see other clients vis verse but can not see them mov
move

spark void
#

So with an auth server, things like movement and rigidbodies could/would be managed serverside and clients would just be receiving that information from the server so it's never an issue of "client synching with client" it's "clients synching with server"?

slow monolith
#

Correct

#

However

#

When you want to move your person, obviously you don't want to wait for the server to tell you that you can move

#

because that's slow and ugly

#

You want to be able to move the character freely on the clientside, and then just have it check with the server to make sure he's in the right spot

#

if not, snap him back

#

You can do this smoothly with clientside reconciliation. Basically the server sends the latest known position, which will be in the past. The client has already moved forward a few steps from that position

#

so you'll have to snap him back, and then rebuild the predicted movement from that server position, to the client's present on the clientside all in one frame

muted garden
#

anyone here use mirrror?

slow monolith
#

Not me

muted garden
#

k

#

:/

spark void
#

Gotcha. Thanks @slow monolith. I'll have to look into figuring out how to code this all out to build a game around it.

slow monolith
#

C# has built-in UDP and TCP listener's and clients

#

use those to build it

#

etc

slow monolith
#

@gleaming prawn The process we discussed yesterday with LocalPlayerRigidBody and LocalPlayerView lerping to it, should work fine with wheel collider cars right?

slow monolith
#

Also should I be lerping to Rigidbody.position or Rigidbody.transform.position

gleaming prawn
#

That question is about physx,

#

Only thing I know PhysX was not made for predict and reconciliate

#

It gets too slow if you reset too many rigidbodies

#

But should work for cars yes

slow monolith
#

Alright

patent fog
#

@spark void I just read quickly but did you try looking existing solutions like Photon ?

hasty sinew
#

I think you should stick with Mirror.

weak plinth
weak plinth
# weak plinth https://youtu.be/qkoZ7d6eQ8k

this video is for the connection to localhost(same pc)...what i am asking for help is what should we do or changes should we make anywhere in order to connect another pc from another lan to connect to former pc ?? @everyone ??

gleaming prawn
#

Since@you are using mirror, their own discord has a big community

#

Maybe you’ll get specialised help there. You need a library and a server to perform punch through

elder solstice
#

Hi, can anybody know one or multiple tutorials or something else to create :

  • Users accounts (with registering and logging in)
  • User's owned avatar items
  • User's avatar customisation with their owned items
  • Items database (logically)
    And I think that's all I need.
    I would like to do this in PHP using MySQL databases, so if you know any tutorial, forum or whatever it would be really nice! Please ping me to answer, thanks in advance!
grim violet
#

pretty much everything you want is there, long read, but worth it

elder solstice
#

Long read is not a problem, Ive already lost like 3 hours making a login and register system that don't work at the end for one of my website

grim violet
#

that one will work

#

its what i started with with most my project

elder solstice
#

Kay

#

Thanks for this

grim violet
#

That code will create your user accounts and database, once you have done this, avatar and items will be easier to figure out. One thing you might want to look at if you are not used with sql db is this link (only after creating the login really so you dont get overwhelmed with all the info): https://www.guru99.com/database-normalization.html

elder solstice
#

Okay, thanks too

glass compass
#

Is anyone knowledgeable with websockets / game servers able to help me with a simple question?

alpine pivot
slow monolith
#

^

glass compass
#

I'm current using WebGL-websockets (https://github.com/jirihybek/unity-websocket-webgl) and am running into issues with the webgl build being able to send messages to the server but not being able to receive messages from the server. In the editor everything works fine. Has anyone run into this issue before?

alpine pivot
#

Looking at the sample code in the repository, it doesn't seems like there is any polling method so this might be a bug.
Perhaps consider using this project instead as it's better supported at the time:
https://github.com/endel/NativeWebSocket

heavy wadi
#

can anyone help me with photon pun ?

#

i am getting this error:
Operation SetProperties (252) not called because client is not connected or not ready yet, client state: Leaving

#

when i leave the lobby (scene), into the main menu scene

heavy wadi
#

nvrmnd fixed it

grand elm
#

How can I select and submit an image via UnityWebRequest.Post in Android?

humble lantern
#

Hello guys! I have a question. I am using Photon as network solution.
In my scene I has a 10 spawn points. When user receive event "ChangePos" I want to change his position to free position, and then set this position as busy. And when sameone left - set his position to free.
The hardest thing is all 10 players already instantiated in scene and when all 10 users receives event - they need to choise free spawn point, and change position to a free one at the same time.

What's you suggestions guys?

spring crane
#

Don't spawn them immediately. Send a network message to the masterclient and wait until spawn point frees up.

glass compass
#

When sending websocket messages how does one typically structure a string so the client knows what to do with a message when it receives it? And vise versa.

alpine pivot
stiff ridge
# humble lantern Hello guys! I have a question. I am using Photon as network solution. In my scen...

It's probably easiest to have one client assign all spawn points (e.g. randomly). You can avoid all the overlapping and get a result that's indistinguishable from a distributed assignment.
The Master Client is a good candidate to take over this duty.
You can store the list of spawn points as room property, which is synchronized and could also trigger everyone to use their newly assigned spawn point.
https://doc.photonengine.com/en-us/pun/v2/gameplay/synchronization-and-state#custom_properties

sick cape
#

Hey, Im currently using photon for a multiplayer game, I was wondering if anyone knew a better server host as photon gets very expensive

#

is AWS cheaper?

stiff ridge
#

You may be mixing up CCU with "users" or "downloads" or so. In general, Photon Cloud is pretty cheap...

#

If you run any servers on AWS you have to make sure they also shut down instances or you might find that "very expensive" is open ended in terms of costs...

sick cape
#

Thanks tobi, I've seen you in every photon help page xD

#

But correct me if I'm wrong:

#

does this mean that if I reach a peak of 2000 players in a month It'll cost me $370? @stiff ridge

stiff ridge
#

Yes, if you have a max of 2k players (at the same time), you'd pay 370€. This includes traffic, load balancing, regions to select from and 0 effort for setting up servers anywhere.

#

Also, 2000 CCU roughly translate to 800.000 MAU. So you need a lot of players (cause they don't all play 24/7, even if some do).

sick cape
#

Ah okay, I didn't realise they had to be on at the same time

#

what's MAU sorry?

stiff ridge
#

What did you expect CCU to mean?

sick cape
#

I thought it meant 2000 separate players on in a month

#

at different times

stiff ridge
#

CCU = Concurrent Users (at the same time)
MAU = Monthly Active Users (any user who played once in a given month)

sick cape
#

Ah okay

#

oh 800,000?

stiff ridge
#

We don't know how many users you got in a month. We can only properly measure how many of your players are playing at some given time. The max of that will be the CCUs we charge you (as we run the servers to handle this max players count).

sick cape
#

ah right $370 is very fair if you have 800k users

stiff ridge
#

As some players don't come back after a few sessions, keeping up 800.000 MAU is also a challenge. You need a properly successful game 🙂

sick cape
#

I understand that

stiff ridge
#

I wasn't sure if I should say anything. When you're unhappy with Photon, we don't mean to talk you into it or so. But this turned out to be a major misunderstanding.

sick cape
#

Yes definitely

#

Thank you

#

👍

#

I'll stay with photon then, but now I have the pain of migrating to PUN 2

#

I am in classic currently

stiff ridge
#

It should not be super painful, really. Get the callbacks right and the renaming of methods / fields is the biggest piece.
Custom Properties got an update in which PUN 2 will not change them locally, until the server "confirmed" the change. This can put you off. There is a setting for that, so ask if this is a problem.
Everything else should be doable.

sick cape
#

Ah okay great

sick cape
#

I just need the motivation to gte on with it

#

Also, I've wondered, why dont big successful games use photon?

#

It seems to be more common to game developers learning to code multiplayer than big commercial games

still laurel
#

hey guys, so, in my game each player is given a "Head" object which has a NetworkTransform

#

for the local player, that Head has the Main Camera as its parent so the Head rotates when the Camera rotates

#

the problem is that that rotation isn't synced with the players in the server

#

however, if I apply the rotation only in the Head object instead of on its parent, the sync happens

#

does NetworkTransform only sync if the transformation only happens in its local reference instead of the world reference?

stiff ridge
stiff ridge
#

Multiple scripts can be observed from the parent PhotonView.

still laurel
#

what I'm doing is having the head without a parent and assigning its position and rotation as the camera's world position and rotation during FixedUpdate

oblique wolf
glass compass
#

@alpine pivot I don’t believe I’m working at that low of a level. I’m using websocket-sharp and hybrid web socket in Unity. The connection is established and I essentially convert a string into bytes on either side then send it to the other.

#

Unless you mean in this case I literally just mention at the start of the string what type of message it is.

fast latch
#

Hi, my xcode is getting null exception but unity does not nor android (about the tcp class)

#
        {
            socket.EndConnect(_result);

            if (!socket.Connected)
                return;

            stream = socket.GetStream();

            receivedData = new Packet();

            stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null);
        }```
Here is the code (this is client side) but i don't understand why there are null exception throwing on iOS but windows and android are fine
#

Any ideas where do i start to fix this ?

stiff ridge
oblique wolf
# stiff ridge As long as your game targets Standalone builds, this is fine. On mobile, it's a ...

have used pun years ago, even bought Bolt Networking before Exit games took it over, pretty much anything with exit games been a bad experience, there are many other solutions that work out better, either its for mobile or standalone, the entire CCU thing is just ridiculous, developers end up with uncertain cost and need to trust that the CCU been given is correct.
PUN is very easy to use but its far from being good. bolt was a better solution till they took it over and i think currently its already the 3rd time its been added to the asset store and twice deprecated.
Also you have no control on server hosting quality and there are also dead zones where you cant host due to having no servers like in Asia region.
Its a good solution for beginners who don't know nearly anything about networking but if you go more deep its better to avoid.
There are so many free solution that does not let you stuck on CCU and there are also free solutions to the backend for spawning servers etc.
The Luck of PUN was that they existed in the time that unity still used a slimmed down version of raknet.
But that is many years ago and lots been changed there are better choices.

grim violet
#

What is the best solution then Dragon

#

when you say "the entire ccu thing is just ridiculous", what do you mean

#

cause every single other service ive seen have that too

oblique wolf
#

For mobile is used Tnet3 that works just fine

#

althought that one was a one time pay $100

#

Forge networking worked fine too

grim violet
#

so they are only lib that let you make a server locally

#

thats why no ccu

oblique wolf
#

I use mirror now mostly as my target is XR development not mobile

grim violet
#

thats another one of those

hallow flint
#

PUN is a relay + matchmaking for the CCU cost

grim violet
#

i think you just dont understand the idea behind lol

oblique wolf
#

you can make a server locally but also in the clod

hallow flint
#

you are comparing apples to oranges here

oblique wolf
#

for the cloud backend there is a framework

grim violet
#

but ditching a well known and used company cause you had a bad experience imo sound a bit stupid

oblique wolf
grim violet
#

you can have your own server with photon too

oblique wolf
#

No , you can host your own but it still links back to their server for the CCU it not the same as a real standalone solution.

#

No matter what you do you still have the CCU recurring payment all the time.

hallow flint
#

and when you host and manage your own servers, you still have monthly costs

oblique wolf
#

but those are more controlable

hallow flint
#

i think you are missing the point of a managed cloud

grim violet
#

i dont believe its a problem, unless ur game is entirely free

#

they handle a ton of stuf behind the hood too

oblique wolf
#

No not really, my background is unix and mainframe engineering over 25 years, there is nothing fancy about setting up those server in the cloud, you just need to have the correct software and good datacentre partners.

grim violet
#

renting a master server plus a couple game server and a login server and all that cost at least 25-30$ a month

#

yet you have no one monitoring whats going on

oblique wolf
#

I been running a game hosting company way before unity was a thing, the time there was Clanbase and IRC ,its really not that hard as you think it is.

grim violet
#

ive ircd to make game too in the past

#

used*

#

stil nothing to compare with photon

oblique wolf
#

#Quakenet 😉

#

hosted also irc bouncer that time

#

and voip servers

#

Its a long time ago 😄

grim violet
#

ive been on the net since 93 too

#

;p

hallow flint
#

🤦‍♀️

oblique wolf
#

been erlier than that

#

im pretty old already 48

grim violet
#

i remember direct connection before that but internet was made public in 93

oblique wolf
#

my first network was with a nullmodem cable via the com port on dos playing C&C before the internet

#

the first lan we made was a BNC network using copper coax cables with terminators

grim violet
#

i downloaded windows 1.0 with a long distance call on a 9600 bauds modem, took 3 days, still wasnt internet ;p

oblique wolf
#

haha yeah 12 FD for that crappy windows

#

and browsers with image blockers so you can see the page data faster

#

those good old times lol.

#

i played quake and unreal online with 400-600 ping hahaha

grim violet
#

i dont remember that has good time, from 93-2000 it was a hack fest and telephone modem was easy to disconnect

#

+++ath0

#

lol

oblique wolf
#

and that was a "good" connection

#

just the noise that came out those modems ... lol

#

actually my first real download was via a radio broadcast to tape and load this tape in an MSX system in the 80's
So you could say that was in a way the first wireless data transfer i did.

grim violet
#

i think photon is still a very good solution compared to many other, i did compare alot of solution and this it probably depends of your need and all but this is clearly able to do all what i want for a lot less trouble that i could imagine

oblique wolf
#

My first computer was 40 years ago, cant believe how fast time flies

grim violet
#

i had coco3

#

i miss that one

oblique wolf
#

Oh yeah every networking is based on your needs for sure.

grim violet
#

with a sound blaster card my dad made for me (he made it himself) and plugued it into the huge speaker we had from the 80's

oblique wolf
#

And as i said PUN is indeed easy but not what i would go for myself.

grim violet
#

thats some powerful beep

oblique wolf
#

I have enough experience to build Cloud based solutions so why i should go to a 3rd party?

grim violet
#

but when you end up having 500 people playing at same time

#

how much its gonna cost you

oblique wolf
#

Currently having servers running across the globe

#

it can start as easy as $5 per node

#

the rela cost is actually traffic

#

and this is priced different per region/country

grim violet
#

you cant handle 500 people on one node

oblique wolf
#

the mount of people depends on how ell you code the game and how much bandwith you need

#

as server does not really require much CPU or memory it pure routing data in most cases

#

Some games i just use "Player hosted" which actually is called a listen server as one player is also running the server, then use the steamcloud to do the matchmaking and natpunch, it is the same as PUN does.
And in some situation i assign dedicated servers to steam and only use the steam matchmaking in that case.
There is also the point why i cant see the more value if you would go onto steam those services are free included @grim violet .
And it comes with more extra's like steamfriends , leaderboards and stuff like that.

#

Mobile platforms is indeed another story, there are so many store around the world for mobile apps.

grim violet
#

i make game that require persistance, dont think steam can do much

oblique wolf
#

you mean your server is persistent?

grim violet
#

aint gonna go throught all of it but from what i know its just basic stuff you can save over there

oblique wolf
#

In general a game is all about data what you store, it could even been written to standalone database server, it really depends on how you want to design it.

#

There not a single network solution that does all the magic you need if things get more complicated.

grim violet
#

but then if you build with steam, you are probably obliged to pass by steam server and share your revenu

#

not sure if that 30% is better than paying a subscription

#

id make it free too if i was steam

#

;p

#

really paying in the end

lunar plinth
#

i'm trying to use mirror for the first time. And i already encountered a problem. How do i count players? Or basically get a list of all the connected players

#

i can't find a function for that

grim violet
#

never used mirror but if there no function to do it you can probably save a list of user that connect/disconnect

storm flame
spring crane
#

@lunar plinth On the client or server?

lunar plinth
#

client, have no idea how to do server side scripts

#

but now when i think about it counting players on server and just sending the data to the clients might be a better idea

spring crane
#

From my limited experience Mirror operates on the assumption that everything the client needs will be sent from the server, so client doesn't necessarily have a list of connections

grim violet
#

i think thats the way to go

spring crane
#

This is only valid on the host / server.

slow monolith
#

How do I get information from my networking thread to unity's main thread?

#

conrurrentqueue and poll it in update()? Is this really the best way?

mellow sapphire
#

Hi everyone, let's say I have the code below:

#

`void Start()
{
photonViewScript = GetComponent<PhotonView>();

    photonViewScript.RPC("RPC_ParentThisObjectToNetInstantiatePrefabsGO", RpcTarget.AllBuffered);
}


[PunRPC]
private void RPC_ParentThisObjectToNetInstantiatePrefabsGO()
{
    this.gameObject.transform.SetParent(goToParent.transform);
    this.gameObject.transform.localPosition = new Vector3(0, 0, 0);
    this.gameObject.transform.localRotation = new Quaternion(0, 0, 0, 0);

}`
#

Would it be cheaper if I did this?

#

`void Start()
{
photonViewScript = GetComponent<PhotonView>();

    photonViewScript.RPC("RPC_ParentThisObjectToNetInstantiatePrefabsGO", RpcTarget.AllBuffered);
}

//
[PunRPC]
private void RPC_ParentThisObjectToNetInstantiatePrefabsGO()
{
    SetParent();
}

private void SetParent()
{
    this.gameObject.transform.SetParent(goToParent.transform);
    this.gameObject.transform.localPosition = new Vector3(0, 0, 0);
    this.gameObject.transform.localRotation = new Quaternion(0, 0, 0, 0);
}`
#

I'm using Photon

grim violet
#

its the same thing except second have an method to access

#

its cleaner for sure 😛

mellow sapphire
#

Because inside the RPC method, instead of processing the contents through the internet, it is instead telling both computers to run the method on their own computer, right?

grim violet
#

thats the method you execute once the data is received

#

photon will get the data under the hood then tell that method (just like you doing with SetParent();) to execute

mellow sapphire
#

And if I do this

#
    [PunRPC]
    private void RPC_ParentThisObjectToNetInstantiatePrefabsGO()
    {
        this.gameObject.transform.SetParent(goToParent.transform);
        this.gameObject.transform.localPosition = new Vector3(0, 0, 0);
        this.gameObject.transform.localRotation = new Quaternion(0, 0, 0, 0);

    }

#

Wouldn't it mean that this method is being processed online instead of locally?

grim violet
#

its still local

#

there nothing that run online from the client

#

photon do that for you

mellow sapphire
#

But why does my game keeps disconnecting then? I don't get it

grim violet
#

that could be something else

#

when does it happen?

mellow sapphire
#

While doing anything

#

I could be fighting a NPC or just walking

grim violet
#

when you get disconnected its either bad data being sent trought photon or too many or anything that will break it

mellow sapphire
#

I have this VR this that I'm working on that just disconnects a lot

grim violet
#

ah not sure about that

#

heard alot of vr people complaint about disconnect

#

not sure if its a common thing or what

#

might be a problem with headset

#

or eyeset or whatever you call it ;p

#

i dont do vr

mellow sapphire
#

When you say data being sent, does it mean something like

photonViewScript.RPC("RPC_Method", RpcTarget.AllBuffered, float DATA);

grim violet
#

yeah

#

that is buffered

#

mean when another player join he will get that data too

mellow sapphire
#

Is that too heavy?

grim violet
#

if you have 5000 buffered thing overtime

#

yes

mellow sapphire
#

And what if I'm not sending any data

grim violet
#

its super heavy

#

even 500

#

;p

#

too much

mellow sapphire
#

Such as photonViewScript.RPC("RPC_Method", RpcTarget.All);

grim violet
#

rpctarget.all is not buffered i think

mellow sapphire
#

True

#

So this isn't heavy then?

grim violet
#

only thing i would use to buffer is the player custom stats or equipments

#

rest unbuffered

#

like shooting or opening a door

#

you dont buffer that

#

if door open 500 time during game play

#

all this will come to the new player joining

#

its unnecessary

mellow sapphire
#

Is it normal to disconnect even while playing alone?

grim violet
#

no

#

bad code somewhere

mellow sapphire
#

Then I don't get it

grim violet
#

i leave my player online for days sometime

mellow sapphire
#

How do I find out?

grim violet
#

testing, profiling

mellow sapphire
#

The Photon part I mean

grim violet
#

recheck all your code make sure nothing run in loop or buffer unnecessary stuff

mellow sapphire
#

Alright

#

Well, thanks @grim violet 🙂

languid shuttle
#

who was the guy who pmed me about photon. cant find u anymore meh

grim violet
#

you usually have an history of people that pmed you

oblique wolf
# mellow sapphire Is it normal to disconnect even while playing alone?

It does not need to be bad code it can be just the photon servers in your region not being good enough.
if you have only a player spawned and nearly no other networks callbacks in your code and get disconnected it photon servers problem.
So to debug you only should spawn and walk around, if that is fine then go to the next step in netcode, if it disconnect you with nearly no network callbacks it is 100% photon cloud service problem as non network related code is irrelevant.

#

@mellow sapphire VR does not really matter, I am a XR developer myself, making AR and VR application.
The difference is the rendering part nothing else in general with exeption of the workflow on art.

mellow sapphire
#

What exactly is a Network Callback?

oblique wolf
#

everytime you callback on a photonview if you using photon

#

an RPC call

#

stuff like that

mellow sapphire
#

I see

#

I use a lot of RPC, however, I'm not sending much information I believe

#

Only making the calling normal RPCs without sending information

oblique wolf
#

you can write a lot rpc in code but its about how many times they are called

mellow sapphire
#
void Start()
    {
        photonViewScript = GetComponent<PhotonView>();

        photonViewScript.RPC("RPC_ParentThisObjectToNetInstantiatePrefabsGO", RpcTarget.AllBuffered);
    }

    //
    [PunRPC]
    private void RPC_ParentThisObjectToNetInstantiatePrefabsGO()
    {
        SetParent();
    }

    private void SetParent()
    {
        this.gameObject.transform.SetParent(goToParent.transform);
        this.gameObject.transform.localPosition = new Vector3(0, 0, 0);
        this.gameObject.transform.localRotation = new Quaternion(0, 0, 0, 0);
    }
#

So

#

I had this example

#

Would this make the network callback lighter?

oblique wolf
#

like i could write an rpc to change my score but it should have something ahead in logic that it only calls it when the score changes

mellow sapphire
#

So instead of setting the parent through the RPC, what I could do, would make just let each computer know that they should process the SetParent method locally

#

Would that make a difference?

oblique wolf
#

This script is only called at start of the object its attached to

mellow sapphire
#

True, but if it was called a bunch of times, would that make a difference doing this

    [PunRPC]
    private void RPC_ParentThisObjectToNetInstantiatePrefabsGO()
    {
        SetParent();
    }

    private void SetParent()
    {
        this.gameObject.transform.SetParent(goToParent.transform);
        this.gameObject.transform.localPosition = new Vector3(0, 0, 0);
        this.gameObject.transform.localRotation = new Quaternion(0, 0, 0, 0);
    }

Instead of this

RPC_ParentThisObjectToNetInstantiatePrefabsGO()
    {
this.gameObject.transform.SetParent(goToParent.transform);
        this.gameObject.transform.localPosition = new Vector3(0, 0, 0);
        this.gameObject.transform.localRotation = new Quaternion(0, 0, 0, 0);    
}


oblique wolf
#

The script is very short as i see you only want to sync a pos and rot over the net at start

mellow sapphire
#

That was an example, but let's say it was on an update method

oblique wolf
#

no never run netcode in updates lol

mellow sapphire
#

Hmm, I am doing that...

oblique wolf
#

thats your problem 😄

mellow sapphire
#

Should I set a bool then?

oblique wolf
#

why you need to update it in every frame ?

mellow sapphire
#

Change a bool though RPC, so both computers know that if a bool is True, than a method should start processing

oblique wolf
#

what data is so important to update every frame?

mellow sapphire
#

I have to re check my code

oblique wolf
#

if you realy want to sync you might be better of writing a coroutine that syncs every x seconds

mellow sapphire
#

That's true

#

Ok, I think I found something that I can start to debug, which is eliting RPCs being called on Update

#

eliminating*

oblique wolf
#

I never use netcode in update, the only thing that updates frequently is pos/rot but only when a player moves and only in x seconds as it uses smoothing between last position and new position.

mellow sapphire
#

That's good to know, because I was honestly getting very worried

drifting ice
#

ok now unity wont install

#

wait how did i get in this channel ignore that

oblique wolf
#

I dont use photon myself, i used it many years ago so i dont know how well you can even tune it.

mellow sapphire
#

Photon there were already a few tutorials, but if I could have swapped to Unity Networking system, I would, but too late now =/

#

What do you use Dragon?

oblique wolf
#

Unity network is easy to use, and its is now taken over by a dev its called Mirror

#

I use mirror, tnet3, forgenetworking.

mellow sapphire
#

Ohhh, I heard about Mirror

oblique wolf
#

although you need to setup your own cloud hosting servers but you can control cost as there is no CCU

mellow sapphire
#

That is true

#

Does the paid version of Photon work faster and better than the free version?

#

And also disconnect less?

oblique wolf
mellow sapphire
#

Oh wow, population one was made with Mirror

oblique wolf
#

Also fallguys

mellow sapphire
#

Jeeez

oblique wolf
#

its free asset, its the fixed unity networking

#

would say the finished UNET lol

mellow sapphire
#

Now I feel that it's too late switch since I programmed a lot already

#

Sometimes Photon is annoying, but maybe other systems are too, I have no idea haha

#

But thanks for the help @oblique wolf !

#

I know a few things about VR if you need help

#

Just let me know

oblique wolf
#

You can get a vps in the cloud to host as low as $5 /month already and you can scale it up on release

oblique wolf
#

I am in VR since cardbox and a preorder vive user @mellow sapphire

mellow sapphire
#

Oh wow...

#

Well... I'll let you know if I need help instead then...

#

😂 😂 😂 😂

oblique wolf
mellow sapphire
#

No way man, that looks amazing

oblique wolf
#

I am one of their partners

mellow sapphire
#

Imagine playing DnD on that

oblique wolf
#

Its what i stepped into as i think it might even outstand VR

mellow sapphire
#

Could be

#

The future is bright

#

I'm working on this

#

Just me...

#

A lot of work

#

Anyway, gotta go to bed

#

Good night bro!

jade glacier
#

I'm pretty sure Fallguys was not Mirror, but Population One for sure is.

#

Onward uses Pun2, Population One uses Mirror

floral turtle
#

Fall Guys was custom iirc, think they used protobufs

gritty wadi
#

how about Phasmophobia ?

jade glacier
#

They use Pun2

#

Mainly for the integrated voice I think

#

Among Us started on Pun2 as far as I know, and then decided to make their own variant of what Photon Realtime is, since they had the skills to do it.

#

Population One is for sure Mirror

slow monolith
#

@gleaming prawn Do you use DOTS or ECS for any of your projects? And if not, do you do any regular multithreading for your server?

Both my UDP and TCP services run on a completely different thread, and they just pass data to unity's main thread, which seems like it would eat up the CPU pretty fast, especially when managing 50+ players. Am I going to run into problems in the long run if I process all of the game stuff on unity's single main thread?

gleaming prawn
#

Lol, that table

#

I won't bother about the fake parts of the video. You guys should be able to realize yourselves

slow monolith
#

Erick did you see my question? Just trying to find out how to squeeze as much performance out of unity on the multiplayer as I can

gleaming prawn
#

I saw, sorry

#

Let me answer

#

I do work with multithreading, but only in the context of Quantum, which has a task-graph system for handling very fast work-stealing MT.

#

So we do a lot of stuff using all possible CPUs during the simulation step.

#

But I do not use unity's MT for spliting tasks between network and simulation.

#

But, if you are "eating cpu really fast" means more than your way of handling MT is bad

slow monolith
#

alright

gleaming prawn
#

Tobias seems to be writing something...:)

#

He works with MT on photon realtime I think.

stiff ridge
# oblique wolf No not really, my background is unix and mainframe engineering over 25 years, th...

You know, this really gets me: Because everything is oh so easy to you, you suggest everyone follows your path and host on their own.
Yes, sure, it's possible to host your game yourself and be happy with any networking solution there is. But you seem to assume everyone can handle servers in a number of regions as easily as you. You state that CCUs are unpredictable in price, then you go on to say server cost is different everywhere and traffic will be the real driver of costs.
It is not trivial for everyone to set up a bunch of servers and maintain them. It should be a conscious decision if you want to handle this or not. Once your game is build with some networking solution, you can not easily rip it out and replace it.
Sorry for my rant. Just wanted to clarify this somewhat...

stiff ridge
slow monolith
#

So regarding multithreading for unity, I should do as much of the work as possible on other threads, and then just queue up an action for the main thread when I need to use unity's API?

#

That sounds like a dumb question, it's late

#

I just dont want diminishing returns for a whole lot of extra work

gleaming prawn
#

1st:

  • both the message processing, and the netcode should be as efficient as possible
#

To take as little CPU as possible

#

Yopu should be able to run 50 players single thread.

#

the netcode processing at least

slow monolith
#

How mine works is, I just pass data between a concurrentqueue

#

is this fast enough?

gleaming prawn
#

no

#

that uses Locks AFAIK

slow monolith
#

alright

gleaming prawn
#

you need to go down the rabbit hole a lot more if you want to use these things

slow monolith
#

What are my options?

gleaming prawn
#

I don't know, because you've been working on your own code for a long time

slow monolith
#

Also, with concurrentqueue, I simulated around 100 connections all sending data at around 60hz. Unity was at around 40% utilization

#

Is this bad?

gleaming prawn
#

But you should be able to use memory buffers, and use lockless CAS operations

#

Is this bad?
Very bad

slow monolith
#

alright

gleaming prawn
#

this looks like MIrror benchemarks... 🙂

#

That run 500 connections but take 90% of CPU with no game logic (this becomes irrelevant, as you can't do an actual game like this)

#

I'll copy here a number I heard...

#

If you have a server with 16 cores, you MAY reserve 1 full core for network processing, for example

#

So your network processing CPU consumption in itself should not take more than +-5% of your tick budget or so.

#

You'll need a lot more CPU to process:
b) basic game logic
c) lag compensated raycasts (if necessary)
d) change-detection and packaging from objects
e) together with interest management (what to send to each client, how to split)
f) THEN packaging these in individual sends to each client
I omitted a) because it is the network IN (receiving inputs from clients)

#

b-e combined should be your CPU bottleneck (and you need to design-for-efficiency the prominent ones as well)

#

But a) and f) should be a very very tiny footprint

slow monolith
#

So the memory buffer you talked about, how complex does this get?

gleaming prawn
#

it's just a sequential memory buffer.

#

I don't know how to answer

slow monolith
#

alright ill do some research

gleaming prawn
#

If you are used to only using concurrency-safe collections, maybe you should not go down this route

#

And it's not a magic thing as well

#

It's not the buffers... it's how you push/pull data

slow monolith
#

Yeah that sounds rather complex

#

for my understanding at least

gleaming prawn
slow monolith
#

This is with no game logic

gleaming prawn
#

you should be able to process 100 connections very fast

slow monolith
#

I think its the dequeueing part which is slowing it down

#

all of my networking happens on a separate thread and it's just the standard C# networking stuff

#

TCP and UDP listeners

gleaming prawn
#

This is designed for safety and easy of use

#

you are probably eating a lot of CPU just with implicit sleep/wakeups and locks (I might be wrong)

slow monolith
#

wait hang on nevermind, just removed dequeing from my server

#

and the CPU was untouched

#

so yeah you're right, might be the networking itself

oblique wolf
# stiff ridge You know, this really gets me: Because everything is oh so easy to you, you sugg...

There are many cases that photon is not the best solution, you are clearly biased or just trying to get more sales for Exitgames, aren't you Tobias who works with exit games for some years already?
Please don't forget this channel is called networking and it is to discuss all kind of solutions, dont try to make this a photon only channel as for help on photon ppl should just go photons support channels rather than Unity's Discord server.
Oh that was the problem with photon too, lack of support.. almost forgot that 🙂

slow monolith
#

Yep my unity server is idling at 42% with and without any dequeuing with 100 clients all sending info at once

#

which is odd because it idles at 32% when none of that is happening

#

gonna see if I can find whats eating up the CPU brb

oblique wolf
#

@slow monolith check if you have automatic lightbaking enabled

slow monolith
#

Where do I check that

oblique wolf
#

windows>lighting

slow monolith
#

I'm going to inspector-> add tab

#

and I dont see lighting

oblique wolf
#

unity 2019?

slow monolith
#

2020.f

#

.2*

oblique wolf
#

Windows>windows>lighting

gleaming prawn
#

Gary, if it idles at 32%, and at 42% with clients, your networking footprint is at 10

#

not horrible, depending on what you are processing

slow monolith
#

Yep, only 10% on the networking side

gleaming prawn
#

And test the server with an IL2CPP release build (headless if possible), not from editor

slow monolith
#

will do

gleaming prawn
#

this should be much faster

#

@oblique wolf there are many people from Exit Games here, and we all answer general questions about networking whenever possible.

slow monolith
#

Also that 42% was also fully dequeing the info and sending it into a pretty long switch case

#

so definitely not bad for 10% at all

gleaming prawn
#

ye

#

I was wondering how you were doing 40% just with networking, that's a lot

#

But keep in mind the a-f list of things

slow monolith
#

Will do

oblique wolf
gleaming prawn
#

you are free to use anything.

#

or do your own like Gary who I'm talking to... You are free to be angry as well. 🙂

slow monolith
#

I don't know why I'm doing this

oblique wolf
#

who is gary lol

slow monolith
#

so many people told me not to

#

too far to quit now 😉

gleaming prawn
#

you are sure learning some things

slow monolith
#

^

#

Okay yeah so my server is idling at 30% even after I removed all scripts and just have a plane

#

very weird

gleaming prawn
#

yes

slow monolith
#

Alright so it was idling high because I wasn't capping the framerate. Full blast UDP with 100 clients caps the server at around 23%

#

that's just networking. No dequeing

#

Adding/Removing from queue seems to add no load to the server, so it's just a matter of optimizing the networking thread now I suppose

slow monolith
#
    {
        new Thread(async() =>
        {

            while (true)
            {

                UdpReceiveResult StartNetworkingUDPReceive = await UdpClient.ReceiveAsync();
                byte[] UdpReceiveResultBuffer = StartNetworkingUDPReceive.Buffer;
                int Code = BitConverter.ToUInt16(UdpReceiveResultBuffer, 0);
                UdpReceiveResultBuffer = UdpReceiveResultBuffer.Skip(2).ToArray();
                HandleUDPPacket(Code, System.Text.Encoding.UTF8.GetString(UdpReceiveResultBuffer));

            }

        }).Start();

    }```
#

This is the receiver code on the server for UDP, not sure what else I could modify

#

oh wait, removed a few debug.logs, goes up to around 14-16% total with 100 clients sending data every 0.02 milliseconds

#

is that acceptable?

#

HandleUDPPacket() goes to nothing, in-case anyone wants to optimize my code some more

gleaming prawn
#

0.02 ms really?

#

use a realistic 0.016 SECONDS between sends (60hz)

#

or is that what you meant? 50Hz?

slow monolith
#

oops yeah changed it back to 50hz

#

let me check with 60

gleaming prawn
#

make it an IL2CPP build, use a stopwatch around you networking code to see how much TIME it is actually taking

#

the one on Unity's main

#

don't use the profiler for that (profiler is good for AB or before/after tests)

slow monolith
#

its still around 15-16% utilization at 60hz

#

let me try a build

#

uhhhh @gleaming prawn In a build I'm down to 1.5% utilization

#

what on earth

gleaming prawn
#

yay

#

That's more like it

#

YOu're good to go... now have fun with b-e

#

that will rake your CPU for real, lol

slow monolith
#

Perfect, thanks

gleaming prawn
#

IL2CPP is at least 4x faster than a Mono build... If previously that was in EDITOR, 10x is expected, yes

slow monolith
#

Wait, no. My unity exe didn't have firewall access, just popped up 10 minutes later

#

It's still running at 15%

#

wtf

gleaming prawn
#

ohhh

#

ok, that looks like threading then...

#

Try something like 32 connections, etc

#

ALso, where are the clients connecting from?

#

I assume from a different hardware

slow monolith
#

Nope all from the same computer

#

100 clients was 15% utilization, 50 clients is at around 7-9%

#

I tried a headless build, same results

#

the UDP listener all runs on a single thread

gleaming prawn
#

that's a bad test

#

because the clients are interfering with your CPU

#

They force context switches on the hardware

#

you must test from a different PC

#

so your unity server has a CPU for itself with minimal context switches

slow monolith
#

alright

gleaming prawn
#

how much is the overall CPU use?

#

including the clients?

slow monolith
#

let me check

gleaming prawn
#

you are probably sturating CPUs already

slow monolith
#

clients are doing about 20%

gleaming prawn
#

ok, not that much

slow monolith
#

server is at 8%

gleaming prawn
#

that looks ok-ish then

#

if you are really testing it

slow monolith
#

It's not interfering with unity's main thread, so I suppose not too much of a big deal right?

gleaming prawn
#

It may work for your needs with that

#

it is

#

you have 50 clients running a thread + unity on each + the server connection threads (50?)

#

This is a LOT of threads to context switch on a CPU with what 4 or 6 cores?

slow monolith
#

4 physical, 8 threads

gleaming prawn
#

ye, 4

slow monolith
#

I changed ReceiveAsync to just Receive

#

down to 4%

#

gonna see if thats actually right

#

yeah that seemed to work?

#

I'm still able to receive packets extremely fast on the server, so I suppose that was the fix. Hopefully you can explain why async does that, when you're back

#

100 clients, sending at 60hz, no more than 5% in the editor for the server

gleaming prawn
#

looks ok then

slow monolith
#

Only 2-3% on headless build. Hoping this is correct this time

#

Yep looks fine this time around

gleaming prawn
#

cool

alpine pivot
alpine pivot
weak plinth
slow monolith
#

@alpine pivot Turns out it's true. I ran debug.log (which bumbed me up to like 7% with it on) and I was getting every packet at like 3,000 packets per second

#

I wish someone told me earlier that networking with async shits on performance

#

maybe its just unity

slow monolith
#

Okay wtf TCP was the same way. 35% full blast on the server end, removed async, now down to like 3%

#

Am I screwing myself by not using async in any way? UDP and TCP run on their own separate thread anyways

weak plinth
#

No, you can just do it the old fashioned way and Poll the socket for readable/writable data

slow monolith
#

I fixed the problem though, by removing async

#

I just wanted to know if there's any downsides to not using async during networking

weak plinth
#

Not really. It has some boilerplate code for ease of use and fault tolerance etc

#

But also a lot of overhead

slow monolith
#

You're right on that last one 😉

cloud orbit
#

Hey guys, anyone have good resources on networking in Unity or a good code base to build off of? I'm using Tom Weiland's code for now but I wanted to check if anyone knew better

#

I'm making a turn-based game so I don't need anything fancy. My plan is to maintain some kind of move history and play it back on other clients when the message is received

#

As with anything though I'm open to any advice

slow monolith
#

I'm writing authoritative netcode entirely from scratch if you need to bounce an idea off of me

cloud orbit
#

It sounds like that is what I'm gonna end up doing. My focus is on getting this game to a playable state asap though so I won't be going too crazy I hope

#

I'll keep in touch though

slow monolith
#

You will go crazy

#

I've been working on this for around 2 months

#

Turn based sounds pretty simple though

cloud orbit
#

yeah that's gonna be a no no for me haha

slow monolith
#

so maybe not as crazy

#

If you don't need hack prevention etc, it can get very simple

#

like 1 week project simple

cloud orbit
#

I'm hoping it's litterally just sending a tcp packet every so often with the completed moves

slow monolith
#

that is very simple

#

C# has built-in UDP and TCP networking

cloud orbit
#

yeah I could always add features as I go

#

I took a course on networking a year ago so I'm familiar with the basics but idek what extra features I would need for this game

#

since tcp has error correction and everything built in and speed isn't an issue

#

you plan on selling your solution?

slow monolith
#

No, planning on making a game and releasing it

#

that could be years though

#

slow and steady 😉

cloud orbit
#

For sure dude, one foot at a time

tiny cipher
#

im looking to make a multiplayer game and i was thinking of using ecs and unity netcode. Are there any good up to date tutorials or something out there?

#

i dont have any previous experience with ecs

patent fog
#

I assume you did your homework and considered others mature solutions.

That being said, even the docs are not up-to-date, so you'll have to dig and try a lot. No prior ECS exp will make it more difficult, I would begin by making up for that first. Prior exp with any other network project should help though.

It's not ready for production. Only for educating or prototyping purposes. If you still put all your expectations in DOTS netcode and decide a commercial release in 2021, it will probs make you miss your target date, you've been warned.

tiny cipher
#

i did use mirror once, a similar thing to unet

patent fog
#

the docs are not up-to-date
Though I must admit, old code still kinda works with up-to-date packages, but many things are getting deprecated

tiny cipher
#

ok

#

bolt use ecs right?

#

because if it does will that be a good learning method for ecs?

patent fog
#
  1. Learn ECS first, it's awesome
  2. If you're not under a deadline to make money, sure go ahead and try it (it's already promising at its early stage). Although If you are, forget 1. and 2. and bet on mirror or alternatives (depends a lot also on the type of game you want)
patent fog
tiny cipher
#

im not looking to make money

#

ok

patent fog
#

Unity bought Bolt but they'll need some time to migrate it to ECS.

tiny cipher
#

ok thanks

patent fog
#

Also they began implementing their own DOTS Visual Scripting tool prior to the Bolt acquisition, now the project is kinda hanged up

#

They also plan to refactor most of their visual graphs and things so they all look kinda the same, so I wouldnt expect DOTS Bolt very soon 🙂

floral turtle
#

for clarification, there is Bolt Visual Scripting, that Unity bought, and Bolt Networking, an Exit Games product

tiny cipher
#

ok, maybe thats what i was thinking of

#

i was thinking of bolt visual scripting

floral turtle
#

ahh okay 👍, just wanted to make sure since it's the networking channel!

tiny cipher
#

ok thanks

patent fog
#

Thanks, I wasnt aware of Bolt Network

tiny cipher
#

so if i want to learn unity netcode the best option is to follow the docs?

patent fog
#

Oh yeah you mean Photon Bolt right ? I thought like Bolt VS for netcode xD

patent fog
tiny cipher
#

ok, ill try and follow the docs then and see how it goes

patent fog
#

One additional note before I go to bed, please keep in mind that DOTS miss a lot of traditional Unity API, you might have to implement your own solutions for things you expect to be basic nowadays in the engine. But the ECS part is already awesome 👍

tiny cipher
#

ok, thanks alot for helping me

patent fog
#

You're welcome, happy coding

weak plinth
#

Hey everyone, I'm currently looking into adding some networked multiplayer to my game, which can also be played single player. I'm currently having some issues trying to find a framework that keeps the same code path between SP, Local MP and network MP for my game logic. Does anyone have any resources (or perhaps any experience) on strategies for how to handle this sort of thing without creating effectively 3 code paths for game logic?

#

I was thinking it might be best to always have the player be hosting their own networked game under the hood, but I've heard this can lead to some issues with certain platforms.

midnight bane
#

I need help with turning my game multiplayer. So far i am using Photon PUN and i have watched tons of tutorials but i haven't been able to implement it into my project. I have created a match making and a waiting lobby system where different clients can join and wait for each other.

Once the game loads, everything f. up.
This is the script that i am trying to run for each player that has joined the game.
https://hatebin.com/hwsqbwkmhm

and This one is the script that instantiates everything that a player should have ( imo )
https://hatebin.com/wlygaeqaqk

And in the picture is my PlayerAvatar Object.

What i am trying here, which i am not sure if it's correct, is that PlayerAvatar object includes canvas for the player and the scripts(managers) that each player needs to have at least one.

And the Player scripts then Instantiates the ScriptableObject of the unit, then the instantiates the unit, And later instantiates the camera for the player.

Which when the game actually start, everything is either mixed or not working at all.

I need help to understand what is going on and how to fix this.

(i am trying to make a moba like game, but everyone has the same unit.
shop , player stats, skillbar bla bla are the same for everyone)

grim violet
#

when you instantiate a prefab for each player they all gonna have the same, if you change stats on it after instantiating those data need to be shared with other too so they do the same

#

each thing you instantiate must hold a photon view too, so might not be a good idea to instiate 3-4 thing for just 1 player, should be one

#

ok i see you got 1 photon view and then instantiating stuff without any it seem, almost there, you must use that photonview from the character to send something like either a rpc or raiseevent to other people so they know what to spawn too for that character, just like that player.Color at the end, no player will know that if they dont receive some data saying hey the color is now this for this player

midnight bane
#

PlayerAvatar ( the one in the screenshot ) has photonview

#

but i am not sure what to do with it. I got confused

grim violet
#

photonview is your link from this game object to other player gameobject with that same id, you can then either observe thing using OnPhotonSerializeView (which is a kind of streaming process between your values and those in the other player gameobject) or use code like RPC or RaiseEvent to send data, this three method do basically the same thing, just share data between people

#

now when you instantiate a prefab with photon, it will instantiate that prefab only, for all character

midnight bane
#

i watched 5-6m dfiferent videos where people jst type cs if(photonView.isMine) { //do things } so i tried to instantiate canvas, camera and managers, in that if but didn't work

grim violet
#

if you start adding more stuff like canvas and all, you need to tell other people too

#

yeah

#

but that is once you receive data

#

when you send data from a gameobject to other client gameobject (the same one)

#

they need to check if the view isMine

#

cause only the controller player holding that gameobject can change it

midnight bane
grim violet
#

PV is commented

midnight bane
#

yeah i knoww, i wrote the red one in paint too

grim violet
#

kk

midnight bane
#

i mean, i have tried this

grim violet
#

but why would that work

midnight bane
#

i thought it guesed it would instantiate

grim violet
#

are you receiving data in start?

#

this is just to instantiate

midnight bane
#

this Start() is just to instantiate the player's unit and camera

grim violet
#

you dont know if the PV is your or not since the item isnt instantiated yet

#

i mean if you instantiate it

#

for sure its your

#

;p

midnight bane
#

here i kinda did the same thing

#

this one runs as soon as the game start

#

and the other one runs after this instantiates

grim violet
#

did you follow the tutorial

midnight bane
#

i did,

grim violet
#

and thought you would not need to read the manual and went in (i did that)

#

;p

midnight bane
#

that is why i am having problems implementing

grim violet
#

you are missing alot of principle

midnight bane
#

they all use new projects

#

i did it in a new project but couldn't implement into mine

grim violet
#

but i can understand because you are trying to add multiplayer to an existing/completing project

#

its hard to do multiplayer, id start an empty project

#

and do my test there

#

could take months before you catch everything for real

#

if you can have an empty project with 2 player spawning, and changing their color so other can see it

#

you will understand everything

midnight bane
#

yeah i think i need more practice over this. i am confused.

grim violet
#

it is confusing

#

hehe

weak plinth
#

@slow monolith I'll send you the link tomorrow. Was too busy to finish it all today.

grim violet
#

took me a good year to understand photon and still not a pro

#

(almost)

#

;p

midnight bane
#

can you at least tell me, if my approach to have everything for a player in one object is a good idea

#

or should i split them

grim violet
#

yes

#

thats how i do my player too, all in

#

except canvas thought

midnight bane
#

they will use the exact same ui and everything

grim violet
#

not sure ui should be a player thing

#

also controller should already be attached to the prefab of the player

#

so when you spawn the player, its there

#

unles you spanw player without controller

#

not sure what is your game exactly so cant tell

midnight bane
#

those "managers" holds various scripts, i wanted to categorize them so i made it like that

grim violet
#

would be easier to have all setup in a single prefab that you instantiate on the network

midnight bane
#

they are in the same prefab ?

grim violet
#

canvas i dont think other player will need to know what sgoing on there

#

since its the personnal player stuff so it can be in the game itself without networking

#

well they dont seem to be in the same prefab since you instantiate them

midnight bane
#

but then if i change canvas wouldn't it change for everyone ?

grim violet
#

what is on the canvas?

#

this player stats?

midnight bane
#

stats

#

shop

grim violet
#

yeah, only your client shouuld see it? unless it has interaction from other player too

midnight bane
#

those Instantiates are like this to avoid conflict

#

actually i don't need this anymore

grim violet
#

client A - have a canvas and shop, then photonnetwork instantiate player which has controller and all already for that player only

#

client B - have a canvas and shop, and the same instantiate for his player

#

each player buy item and equip it

#

what they need to share for network is what they just bought and if its equipped or not

#

so that could be a small as 2 int sent over the network to other player

#

saying hey i just bought this from the shop and equipped it

grim violet
#

so other player will say ok, that player have this and t his, lets spawn it for him locally

midnight bane
#

my shop is kinda different

grim violet
#

thats how it shuold be

#

oh

#

well yeah like i said

#

i have no idea how you setup your game lol

#

could be totally unusual

midnight bane
#

i have a few abilities in a line

#

when i buy one

#

it shows like this

#

so it's not a shop it's an upgrade panel

grim violet
#

still the same

#

if all player have the same canvas spawned and instantiate on network, and one player decide to buy a skill

#

all player will have it?

#

it should be local only

#

other dont have to know what skill you got

#

they need to know when its being in action thought

#

to spawn the VFX and damage or whatever

#

thats why canvas should be local, its just about ui, ui shouludnt be networked unless your game specifically use that in the network

#

but clicking a skill, you dont network the skill being clicked, you network the VFX being played from X player, and who hes targeting

#

i think you are missing some of the logic of networking, thats why you should start slowly

#

with a basic thing

#

like pong game

#

or something lol

#

i know it suck but, gotta start at bottom

midnight bane
#

i guess so, i can feel that i am missing way to much to implement a correctly functioning system into this project right now

grim violet
#

yeah you probbaly achieve it but gonna take alot of time and spaghetti code

#

the headhach coulud be less starting from A

#

people at photon highly recommend following the tutorials closely until they are completed

#

they must have alot of succesful client that did it hence why they recommend it

#

id start with all those

#

its always faster when learning properly anyway

#

might take just a week or two and you will catch it

midnight bane
#

yeah, i been following the tutorials in a new project and this one at the same time. the new ones worked but this didn't :P guess i will practice till i say '' ooooh''

grim violet
#

hehe

#

i rushed in without looking at too

#

took a while until i decide to understand every single word i was reading

midnight bane
#

i started unity like 3 weeks ago.

#

never felt complicated

grim violet
#

thats alot at same time

midnight bane
#

since i know c# already

grim violet
#

did you use other engine?

midnight bane
#

nop

grim violet
#

that help

midnight bane
#

well warcraft3. world editor :P

grim violet
#

i had only experience with ogre3d that i used 20 year ago

#

and gamed past 20 year so

#

rusty

#

lol

midnight bane
#

:P

#

well i guess it's time to slow down and study again so back to work :P

grim violet
#

i think your doing good thought for a beginner

#

its really just the logic behind the networking and P2P

#

that you seem to be mising

midnight bane
#

i am good at this. once i understand what i am doing :P which i hace not idea what i am doing about this networking stuff atm :D

#

thank you for the advices

grim violet
#

np

slow monolith
#

So say a UDP snapshot packet comes in on the server out of order, do I just ignore it?

somber drum
#

I'm not sure if this is regarded as #497872469911404564 but it feels more networking related so I'll just ask here: What would you say the bare minimum/essentials are for a server online a month on higher capacity (100 players max) in a fast paced setting? I'm currently just using steam's connectivity for testing but obviously in a live environment I would want actual dedicated servers, to which I have no idea what's necessary

slow monolith
#

Nobody can answer that. Every game server is different.

somber drum
#

Right so if you were to guess a game like Rust?

slow monolith
#

I hear rust servers are pretty demanding

#

but I've never ran one

somber drum
#

what does pretty demanding ring in your mind? (if you care to answer if not thanks all the same)

slow monolith
#

not a xeon

#

anything with >4 cores and a decent clock

somber drum
#

So I guess this is the bare minimum that I would scale off

RAM: Minimum RAM requirements is 4GB of RAM, but 8GB+ is recommended for optimal performance.
Operating System: Windows 7, 8.1, or 10 or Linux: Ubuntu, Debian, Fedora, or CentOS
Processor: Dual-core 3.4GHz or greater
Disk Space: 32GB+
#

not a xeon noted 🙂

slow monolith
#

most multiplayer servers are single threaded anyways

#

besides maybe another thread to handle networking

#

so clock speed is very important

somber drum
#

Would anyone recommend Multiplay over more traditional options?

#

my understanding is they are managing the cloud where I could in theory do that myself if we're both utilizing aws services?

slow monolith
#

what traditional options

#

like p2p?

#

@gleaming prawn How would I deal with out of order UDP packets when creating an online game
like say I'm expecting packet 8, and packet 9 comes in, and then packet 8
just skip packet 8 entirely?

#

I think that's what unity said they did for their multiplayer demo, just confirming though

jade glacier
#

Depends on if your code has any need for packet 8

slow monolith
#

It would just be for movement

#

so I could probably afford to miss it

jade glacier
#

In my system I kept it in the ring buffer, since it was useful for extrapolation.

#

Or if it hadn't finished consuming that frame

slow monolith
#

How do you do your extrapolation anyways? Since that's on my to-do list

jade glacier
#

You don't consume frames the moment they arrive typically. They go into a buffer.

#

If a frame doesn't arrive in time, you make a guess at it.

slow monolith
#

Ok

#

How common is packet loss in general for UDP?

jade glacier
#

No idea how to answer that

#

Depends on the person's connection. But you have to plan for the worst.

slow monolith
#

yep

loud geyser
#

Howdy. I am working on a 1v1 platform fighter. I am aware of my options ( Mirror, Forge, etc. ).

Which network engine would you recommend for really precise netcode requirements?

oblique dragon
#

@loud geyser try colyseus

rocky drum
#

@loud geyser I love mirror, and the syncs are really precise

gleaming prawn
#

for a fighting/brawler none of these work (like these genre players expect)

#

They all expect you to have rollback netcode

#

You have 3 or 4 options:

  • write your own rollback netcode (over any relay or other type of transport layer)
  • adapt GGPO (over a relay or another transport layer)
  • Photon Quantum
  • There's another company that offers a predict/rollback netcode engine, but I'm not sure it is compatible with unity (and forgot the name - but a google search could find)
weak plinth
#

is anyone familiar with Photon networking? i have this issue where i control my friends game, and he controls mine. And thats not every optimal when trying to make a multiplayer fps 🙂, idk if its a problem with the code, or the photon. (i follow dapper dino's tutorial)

#

which isnt a thing

gleaming prawn
#

IsMine should control yours

#

You may be getting an issue with the camera

grim violet
#

do you have camera under player?

gleaming prawn
#

Make sure the camera is activating to the same object that IsMine is giving true

#

Ye, my suspicion is a camera confusion

weak plinth
weak plinth
gleaming prawn
#

You should only have ONE active camera

#

The one from the player you control, that's it

grim violet
#

but if 2 player spawn, you will see second camera

#

so yeah, 1 camera

#

should be outside of player, following player with a script

gleaming prawn
#

or disable the one from the object where IsMine is false

grim violet
#

yeah

#

that work too

weak plinth
#

kk lemme try

weak plinth
#

its a first person shooter game

grim violet
#

you remove the camera from the player and place one in the root of the scene, then add a script to the camera with something that follow the player in update or something, you will also check if the player is your
but the method erick said is quicker and easier

#

just disabling the camera of the player if the player isnt you

weak plinth
gleaming prawn
#

You can make it "follow" in FPS mode making it snap to the head position

grim violet
#

o_O

gleaming prawn
#

this looks ok

weak plinth
#

camera or cinemachine camera? i heard alot of good stuff about cinemachine but never used it

gleaming prawn
#

are you setting active false to the ELSE case?

#

Or maybe starting both as innactive

#

You probably have a camera active on the second player (most likely case)

weak plinth
gleaming prawn
#

Check in the hierarchy playing from the editor

#

I know it's two instances...

weak plinth
#

isnt that how u do it?

gleaming prawn
#

Check in the hierarchy that one of the cameras is off

weak plinth
#

ohhhh

gleaming prawn
#

Depends if the camera starts as active or not

#

Your code is not wrong, if both cameras are created as OFF/Innactive

#

But if they are created active, you need an ELSE in your code

#

or invert the code:

  • SetActive to false where IsMine == false
weak plinth
gleaming prawn
#

still nothing?

weak plinth
#

im just showing u

#

i need to rebuild it and test it out

gleaming prawn
#

ok

weak plinth
#

ayyy it works

#

thnx brother

#

really appreciate it

#

both of you

grim violet
#

you can if you want to scale your character

gleaming prawn
#

There's a discord for photon as well

#

I can't post a link here, but send me a PM if you want

gleaming prawn
#

sent via PM

dire ridge
#

Im Using Nakama And I trying For Received Message in Match, But Received Message Doesnt Work. Why?????

lunar plinth
#

I'm trying to solve quite a simple problem but i can't think of a solution. At the start of every round i try to spawn players using an rpc. But how can i get a players team its in his object im using photon pun.

#

Like basically how can i get a specific object using players id

lunar plinth
#

solved it

cloud orbit
#

Hey guys, trying to make my network client run on a seperate thread (I assume that this is better than running the client logic in an update function or smt). Is this the ideal way to do it?

    listen_thread = new Thread(new ThreadStart(ListenForClients));
    listen_thread.Start();
#

People are saying not to use abort to kill threads and to leverage processes instead but I'm not sure what that means

cloud orbit
#

Nm I think I have found a better approach using asynchronous programming

weak plinth
#

It means to not call abort on the thread

#

But rather to make a while true > false

#

So that it ends itself

#

And async has a tremendous overhead

midnight bane
#

I have a question about Photon, or any alternatives. So i have been using Photon PUN 2, and trying to learn how it works and as far as i understand, the multiplayer uses a "Master Client" which i guess is where a player in the room, acts as a dedicated server. Which i kinda find it useful but not the method i wish to practice on.

So can anyone recommend me a framework that i would help me use a server ( like Amazon's free 10gb servers ) as a server, for the rooms. ?

I have found out that photon also has servers, but i cannot find any tutorials

jade glacier
#

@midnight bane The relay (hosted by Photon around the world) is the server. The master client is just a client that carries a special flag saying that it is the default controller of room objects, and can be used as the final word on states when you need that.

#

Typically for this reason, Pun2 games typically lean on player authority, rather than server authority.

midnight bane
#

so it actually runs on photon's servers not on the client's hardware ?

jade glacier
#

The relay knows nothing about your game (unless you make use of server plugins) - it is just there as a communication hub between clients.

#

The relay servers are what PhotonEngine hosts

#

So all players first connect to the MasterServer (matchmaking) and find a game room, or create one. Then they disconnect from the matchmaking server and join that game server and its room.

#

At that point, all clients can send messages to one another through that room relay.

#

So there is no server that you have to create or manage. That is the positive and negative of Pun2. Not having a server makes deployment very easy, but it also means that your game should not rely on the need for server authority.

midnight bane
#

so as i understand. Until a room is created, the players are not actually connected to a server.

#

that is fine, but i don't understand what actually a relay server is

jade glacier
#

They are connected to a different kind of server

#

You first connect to the MasterServer, which is the matchmaking server.

#

That is where you find/create rooms

#

The game server is the relay server

midnight bane
#

yeah i have done and understand that part, but then if relay server is different from that server, where is it actually

jade glacier
#

It is called that because it is a Server - the clients connect to it like a hub and spoke. It is called relay to make it clear that it is very specifically just there to manage connections and communications between clients.

#

If you use Mirror for example, your server is a Unity instance, running on a machine, and all clients connect to that.

#

So that is either hosted somewhere if you want a high quality server, or you let a player host, and everyone has to make use of Nat Punch or backup means like a relay server to talk to that player who is the listen server.

#

With Pun2 the server is always the Photon hosted server. But it knows nothing about your game.

#

All game logic happens on the clients. The only exception is if you use a server plugin, which is a special DLL you make for the relay that gives it some understanding of your game.

#

The relay is the cloud servers.

#

Just like any other cloud server... the only difference is it knows nothing about your game. It is just a generic communication hub.

midnight bane
#

wouldn't it create latency difference between the player that hosts the game, and the others ?

#

or make the room shut down if the player who is hosting leaves

jade glacier
#

If you try to make a client act like a server - which you don't want to do.