#archived-networking

1 messages Β· Page 65 of 1

gleaming prawn
#

Didn'tz understand the question

#

You mean GGPO?

#

GGPO is just 5% of what you'd need, and I'd argue that GGPO is not the way to go for an RTS, because it's not a 1v1 kind of game

#

And also it is predict/rollback, you need lockstep

#

First:
a) write a deterministic simulation (forget all unity libraries like navmesh, physics - these are useless for these kinds of game);

  • you need to write a flow-field/influence-map path finder
  • use fixed point numbers (Q48.16, Q5.3, etc etc), so you are cross-platform determinsitic
    b) server in determinism is only used to batch and manage input distribution between the clients, and serve as a source for clock sync (hardware clocks drift), so you keep everybody on the same timing;
    c) THAT is if you really want to do an RTS (and not other kind of game).
#

The number of units the game will handle has NOTHING to do with netcode when you use lockstep in particular... it has to do with how efficient your simulation code is...

#

But it should be no problem writing a game with 10.000+ units...

#

I'm currently working on a game with 10k+ zombies + 8 physics-based cars at 30Hz in full predict/rollback mode (not lockstep)...

#

But again, it really depends on your experience.

#

disclaimer: I work at exit games, and I'm a game engine guy, part of the team who writes Photon Quantum (deterministic game engine).

wet meadow
#

Thanks this question gave some nice insights on RTS networking.... Another thing how RAM and CPU side of game going to be handled? 10000+ units is pretty heavy you know. Also how much input delay is there in the determinism model?

gleaming prawn
#

predict/rollback is 0-delay...

#

lockstep is a tradeof

#

you add input delay proportional to your ping

#

IF you have the server to mediate things (that's what we have)

#

so players on good ping can have very very small delay (in lockstep... in predict/rollback it's 0)

wet meadow
#

How map generation sides of things gonna be handled?

#

For static objects that'll be loaded first ofc

gleaming prawn
#

If you do procedural generation, just define a seed (from server?) an generate locally on both machines using a deterministic approach...:)

#

The seed will give you the randomness factor

#

Remember that if you want to do an RTS you need your own "physics" and path finding anyway, so it's all custom

#

Forget the naive Unity default stuff, that won't cut for a proper RTS

#

If you just want to create a toy game, for hobby, and you accept things to be a bit "crappy", and you are ok with a low unit-count (in the hundreds), so maybe a normal state transfer would be ok-ish

#

But if you really want to do a proper RTS, start by studying how real RTS are done

#

Fixed Point number implementations in C# are public domain, you find several

#

just search stack overflow...

#

But finding stuff like flow field path finding is another story... You find good guides on the topic

#

But don't expect to find (a lot of) free libraries for this (at least not for everything - you might find a few useful things here and there)

wet meadow
#

This is the project that I am working for.

#

Tried RTS in unity

#

but soon realized it's not just worth it.

gleaming prawn
#

AFAIK AoE is deterministic

wet meadow
#

About pathfinding custom made navmesh is better or A*?

gleaming prawn
#

Unity as a rendering engine is excellent

#

Forget navmesh

#

RTSs use Flow Fields

#

navmesh will NOT work for an RTS... It's not a problem with Unity's navmesh... You need a flow field...:)

#

A* is a search algorithm (a specialized Dijkstra). It is used internally in many navmesh path-finders in one form or another... Flow field uses a regular Dijkstra search AFAIK.

#

So the question is not to A* or not, but actually what you need as PF data structures and algorithms... Forget pre-done libraries...:)

#

Also notice that Unreal is NOT deterministic either... So Unity is not at all BAD... It's just that RTS are a different Beast, really...

#

You can do RTS with any engine, you just throw away their default libraries (for physics and PF, etc) and use just the rendering, asset pipeline/tooling and build-runtime capabilities (which is not a small help, it's great)

#

RTS do NOT use regular physics engines as well..

#

So you won't see an RTS using bullet, havok or PhysX... They use custom simplified/super-cheap collision detections, otherwise it would not scale to 1000+ units...

wet meadow
#

Think we won't be using those. We have to make ourselves.

gleaming prawn
#

Yes

#

That's the only way IMHO.

#

You are not trying something easy TBH

#

IMHO this is not a good starting project if you are not experienced in game networking

#

Definitely not good as a first project at all

wet meadow
#

We have small team working on

#

currently working on converter side

#

soon will switch to unit testing

#

to make the converter compatible with what we are doing

gleaming prawn
#

I have 14 years game programming experience, and I would NOT do an RTS unless I had a very good team with me...

#

And making an EMULATOR for an existing older game is even more difficult

wet meadow
#

We are deciding which approach will be best.

gleaming prawn
#

RTS you need lockstepping, pretty much 100% that

#

unless, as I said, you are ok with a sub-par implementation to hold just a few hundred units in LAN environments

wet meadow
#

We are simply converting asset to a new form

#

pretty much make a new game out of it

gleaming prawn
#

That's as much as I can say.

wet meadow
#

goal isn't as same as the way AoE genie engine works

#

File loading and all stuffs are handled differently

gleaming prawn
#

Also you know you are in a legal gray area (if not 100% ilegal), so you won't even be able to use tools like ours.

#

because we can't support that.

wet meadow
#

no we won't supply the game asset

#

you need official game

#

to make things work

gleaming prawn
#

Anyway... Try to search these keywords:

  • float field or influence maps
#

This will be a good way to start on path finding for RTs

#

and go straight to a FixedPoint number implementation

wet meadow
#

project is similar to this

gleaming prawn
#

Don't waste your time with float

#

I know what you mean...:)

wet meadow
#

btw, navmesh accesses less array indexes or what?

#

compared to flow field?

#

so far what I know is flow field does BFS search over the map

#

then get direction out of it

#

ideal for lots of unit on one target

#

but not so much for multiple target

#

A* becomes viable at that time

#

If navmesh is done right then it should give faster and more smooth pathfinding or what?

gleaming prawn
#

btw, navmesh accesses less array indexes or what?
This is only useful for low unit count, individual targets

#

You should start finding that yourself, where the tradeof lies... You'll MAYBE need both approaches

#

Don't start hanging to use Unity's navmesh though (just because it's easier for you). It has a major problem:

  • it is NOT determinsitic, so youΓ„re done (you can implement a custom navmesh path finder for individual units);
#

In the end you might need both Flow Field (much much more efficient for group path finding) AND individual path finding (over the same data structures you build for your flow field)

#

It will be cheaper and simpler to build a Dijkstra for flow fields + a tile-based A* for invidual Units

#

Unity's navmeh would be useless, as I said...

#

Need to work here... That's as much as I can say... Start by understanding that you need determinism, so unless a library is guaranteed to be cross-platform deterministic, forget about it...:) This will save you weeks/months of unnecessary headaches (that's my hint)

wet meadow
#

Custom navmesh algorithm can work? Having control over grid and terrains?

gleaming prawn
#

I would personally do what I said above:

  • both flow fields and individual cached paths (using A*) over custom tile-data
#

Navmesh != tile based

#

If you implement a tile for flow fields, it's just much easier to just use the same data for A*

wet meadow
#

currently plan is combined solution of A* and Flowfield ofc.

gleaming prawn
#

There's no point in implementing a complete navmesh (which is a different approach, and will be useless for the FF)

wet meadow
#

but looking for every solutions possible

#

before doing actual pathfinding thing

gleaming prawn
#

Navmesh can be cheaper IF done right (for the individual paths)

#

But a hierarchical tile structure can do the same in the end

#

I'd do hierarchical tile-based... Would not touch navmesh

#

Need to leave now... Good luck with the project...

wet meadow
#

Hardest side of navmesh is determining polygons and vertices?

#

you can answer later if wanna

gleaming prawn
#

Don't have anything else to say

#

It's just that it looks a waste having to code two data structures, where one would do

#

I'd not START with navmesh at all

#

First use something that solves both... Later add in an alternative

#

Navmesh is NOT the first for an RTS..

#

Remember that in either case you'll need to code from scratch

wet meadow
#

thanks you for helping.

pastel linden
#

Anyone here with experience/recommendations for different networking engines for turn based games with only discrete game states? I assume some corners can be cut when latency at around 1s is acceptable

jade glacier
#

you shouldn't be seeing 1 second of latency unless your transport is like yahoo mail LOL

#

What do you actually need from your engine? Because what you likely just need is a cloud service.

pastel linden
#

Some kind of matching and persistent game state, so an external service would probably be smart

jade glacier
#

I don't have enough experience to tell you which on would be good/bad - but most of them should have some tutorials for dealing with games - especially turn based games.

#

Ideally I would think you would want one that can run C# scripts? So that your Unity versions and the cloud server can run the same simulation code and share your library.

#

but.. way out of my wheelhouse - so I would take anything I say with a grain of salt.

pastel linden
#

I'm on a similar boat, why I was looking for opinions on technology. But thanks a bunch anyway

#

Running similar code would be preferable

vernal remnant
#

gonna ask my question again...
Do I need both netcode and transport or just one? are they both different models?
Going from the documentation if i wanted dedicated host / server authoritative I would want netcode or am i misreading the doc?

jade glacier
#

I don't know what cloud options like AWS give you for being able to play around with them for free, but would be good if you can to just make a quick sample tick tack toe game in a couple of the options just to see the workflow and api documentation. @pastel linden

pastel linden
#

Huh haven't seen much mention of AWS for unity, mostly photon and such. Wonder what strengths and weaknesses are between these

jade glacier
#

Photon isn't going to do any of the database type stuff, its more for relaying messages between realtime games. It can be used for turn based, but I think its largely the wrong tool for the job depending on how much meta data you need to save pre-post game and such.

stray scroll
#

@vernal remnant If you simply check the dependency of the NetCode in the package manage, you'll see that DOTS NetCode is dependent on the Transport package.

#

If I'm not mistaken, the Transport package basically contains socket wrapping code, which handles the connection.

weak plinth
#

I've noticed that trying to freshly import a project which depends on netcode is a real pain (unless I'm doing something wrong here). The problems that I'm having are that
-Unity won't compile certain components (treating them like missing scripts on my prefabs), like a PlayerId component for example, unless I fix all compiler errors
-I can't "Generate Code" on my ghost prefabs because those components are "missing" (not compiled)
-I have systems in my project which make use of those generated ghosts/collections (to actually make use of netcode in meaningful ways), so clearing out my generated code so that PlayerId can finally compile means that those systems are now throwing errors & PlayerId still can't compile, meaning I still cannot generate new code for my ghost prefabs or collections.
This feels so cyclic. Am I missing something here to make this less ridiculous?

jade glacier
#

It is all preview, so you are playing with bleeding edge stuff there.

gleaming prawn
#

bleeding a lot...:)

weak plinth
#

I mean the only way I can think of getting this to work is commenting out all the netcode bits in my systems (which is alot), clearing all genrated code away, allowing it to compile the data components, generate the collection code, then going back to uncomment all the code I commented out (inevitably, with enough code I'll forget to uncomment something somewhere)
Maybe there's some solution to this with asmdefs, partial classes, or something else

crude night
#

Good evening first I want to clarify that I am French and that I have trouble understanding and making myself understood
I will try to describe my example and my problem in the best possible way

so to start in my example:
1 The client requests a connection to the server
2 the server responds accepted or not, if yes the server generates 2 variable which and the position and rotation then send it back to the client
3 the client receives and appears the chosen one the server

So far so good
4 the client sends the input to the server
5 the server processes the input and changes the state

so we come to my problem
the server needs transform.forward and transform.right to allow the client to go in the chosen direction

so I would like to know how to manage this because to prevent cheating it is the server that manages all the player's state and objects

jade glacier
#

You seem to basically be asking how to make a standard Server Authority game.

#

You can play with Photon Bolt for free, it was designed based on that spec.

crude night
#

I would like to start from zero create my own base and understand the different problem

#

thanks i will watch this

jade glacier
#

Then the article above

#

Watch the video on Overwatch's networking as well

stuck hinge
#

question: if a command packet is lost, does the client resend it ?

#

or do i have to check that it was sent properly

crude night
#

Watch the video on Overwatch's networking as well?

harsh dew
crude night
#

thank you

jade glacier
#

@stuck hinge You are kind of leaving out what your game type and sim type are, so that totally depends. If its not lockstep and its a realtime fighting type game you typically send the last X ticks worth of updates every send, so if a tick gets lost you might still get a repeat of the info to the server he next time.

#

When that all fails and the server gets a buffer underun, you will extrapolate inputs (make a guess of what the player likely was doing... like if they were holding down W.... they likely still will be)

#

Same advice as was given to the previous guy... read/watch the things above

stuck hinge
#

@jade glacier Thank you so much for the reply. Currently I am trying to understand the primitive parts of this. The issue is that the server gets a command from the network player to spawn their character controller GameObject, in the case that the client fails to send the packet or it gets lost in-between, will it act like a TCP packet and retransmit until the method executes on the server? The client only calls the command on the Start() function of the script. meaning it only gets called ONCE when the player connects.

jade glacier
#

Most udp transports have reliable and unreliable options

crude night
#

each input must be transmitted in a different message or can the customer send several input in a single message?
for example at the end of each frame the client checks the input which we change and sends them in an array of bytes?

#

what and the right way to do it?

jade glacier
#

You want as much as possible to combine and pack every tick into its own message. That includes and historical inputs you want to pack in there as well. Packet overhead is something worth avoiding.

native anchor
#

hi guys im using Mirror and I believe that most of what they have is based off of UNET and I have a problem when making a short variable

public const short PlayerPrefabSelect = MsgType.Highest + 1;

this line throws an error saying that I cant implicitly convert a MsgType to short

#

im using unity 2019.3

jade glacier
#

so cast it?

native anchor
#

how do you cast an enum to short?

crude night
#

@jade glacier I did not understand very well, sorry I am French I have a lot of trouble, so I can combine the input?

#

I may not have understood the rest

jade glacier
#

yes

crystal helm
gleaming prawn
#

Regular .net http works. And there are several http helper assets around (you do not need anything azure specific)

crystal helm
#

hey @gleaming prawn thanks man, is there any links or example of implementation you can post here please? im pulling last few hairs hahaha

#

I tried this code from Unity but didn't get past EnsureSuccessStatusCode()

#

public async Task<string> PostAsync(string uri, string data)
{
var httpClient = new HttpClient();
Debug.Log("Before await");
var response = await httpClient.PostAsync(uri, new StringContent("myName"));
Debug.Log("After await");
response.EnsureSuccessStatusCode();
Debug.Log("After success");

    string content = await response.Content.ReadAsStringAsync();
    string result = null;
    Debug.Log("RESUlT is " + content);
    Debug.Log("Before Run");
    return await Task.Run(() => content=result);
    Debug.Log("After Run");
    Debug.Log("End " + result);
}
crystal helm
#

i'm quite a newbie on this, found a way to start getting results from azure's function in case it helps anyone https://stackoverflow.com/questions/60501681/azure-functions-http-trigger-unity3d-2019-3/60502808?noredirect=1#comment107034674_60502808

crude night
#

how to manage 20 snapshots per second?

crude night
#
if (frameCount < tickRate)
            {
                frameCount++;
            }

            if (frameCount == tickRate)
            {
                frameCount = 0;
            }
            else
            {
                yield break;
            }
#

is this a good solution?

#

tickRate and set to 3 which is the division of 30 frames per second

#

60 frames per second sorry

stray scroll
#

What? Nonono

#

You want to separate your send frequency from regular render framerate?

crude night
#

I would like my server to send 20 snapshots per second knowing that the server and the client are running at 60 fps

#

with the code i showed it works fine but i would like to know if this is a good way to do it

stray scroll
#

It's not

#

You can't be sure that client or server always runs at 60 fps. Bad practice for client, and will most likely drift.

crude night
#

how can i proceed?

stray scroll
#

I sent you a link to read

high night
#

@crude night
You must have a network time in your networking asset

You can use that to figure out which frame should a client or server be simulating

#

Network time is supposed to be synced between server and client

#

watch out for lagspikes and pauses though
time will not stop meanwhile
after some pause, network time might say target frame is 1000 frames away

#

you will often have your unity frozen when you pause or debug if you dont deal with that

#

.
I mean if you do this like i did:

// update until in sync with networktime
while(sceneTimeFrame < networkTimeFrame){
       UpdateScene();
}

and have networkTimeFrame return something like:
(int)(networkTime / 0.02f)

crude night
#

sceneTimeFrame what is Time.time?

#

really sorry if i seem stupid but i'm a french guy who has a hard time understanding and making himself understood in english

high night
#

@crude night
what i said might be confusing for snapshot interpolation i think sorry for confusion

#

You don't update the scene by simulating in snapshot interpolation afaik.
So don't mind what i said, it was probably irrevelant

crude night
#

okay thank you my brains started smoked lol

high night
#

i am sorry πŸ˜…

crude night
#

I have a little problem I would like to store the positions in a list and delete the one that is 1 second

high night
#

you can know which frame you should be on like this though
(int)(networkTime / 0.02f)

#

this is for 50 fps

crude night
#

I show you the function

public IEnumerator RemoveIfExpireTime<V>(Dictionary<float, V> collections)
            {
                foreach (KeyValuePair<float, V> kvp in collections)
                {
                    float timer = (Time.time - kvp.Key);
                    int seconds = (int)(timer % 60);

                    if (seconds >= 1)
                    {
                        collections.Remove(kvp.Key);
                    }
                }

                yield return null;
            }

high night
#

/0.016f for 60 fps

crude night
#

I get this error
Collection was modified; enumeration operation may not execute.

high night
#

dont remove elements while iterating in list
@crude night

crude night
#
public IEnumerator LoopDeletePositions()
            {
                while (true)
                {
                    yield return RemoveIfExpireTime<Vector3>(positions);

                    yield return RemoveIfExpireTime<Quaternion>(rotations);
                }
            }

I call the function in a loop like this

high night
#

add items that you are goimg to remove in a new list

#

then delete while iterating from the new list

#

its like cutting the branch you are standing you know
@crude night

#

modifying the list you are iterating i mean

crude night
#

I understand for the branch lol
to delete so i may understand the list in court will keep the collections?

#

it will increase for nothing

high night
#

i dont understand that

crude night
#

you told me added the items I need to delete in a new list
May for the first list which contains all the items I do how to remove them bad

high night
#

you iterate in that new "toDelete" list
and delete that element in the original list

#

@crude night

crude night
#

I don't quite understand an example please?
I tried things but I got a unity freeze 😦

gleaming prawn
#

@crude night you need to read the references and understand...

#

Code for this would be a lot more complex than what you are trying to do.

rancid anvil
#

Why are all players rotatate? Networking problem please help me

#

@high night

high night
#

you have given no context pretty much

#

How do you expect me to help you with such a question

#

That doesn't sound like a question. That sounds like your expression of your confusion lmao

#

Are you asking how to sync rotation of a character? @rancid anvil

rancid anvil
#

Well

#

I have already sync it

#

But even the other player rotate

#

@high night

#

I tried with if islocalplayer

high night
#

the other player is localPlayer too then

#

are they spawned from the "player prefab" ?

rancid anvil
#

Yes

high night
#

try printing isLocalPlayer

rancid anvil
#

`

high night
#

before the if

rancid anvil
#
 using System.Collections;
 using UnityEngine.Networking;
 
 public class Movement : NetworkBehaviour
 {
     public float speed = 1.5f;
     public float offset = 0.0f;

     public Rigidbody2D rb;
    
     void Start (){
         rb = GetComponent<Rigidbody2D>();
     }
     void Update ()
     {
        if(!isLocalPlayer){
            return;
        }
        //ROTATION
        
        Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
        difference.Normalize();
        float rotation_z = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
        if(isLocalPlayer)
        rb.transform.rotation = Quaternion.Euler(0f, 0f, rotation_z + offset);
        

        //MOVEMENT
         if ((Input.GetKey(KeyCode.LeftArrow))||(Input.GetKey("a")))
         {
             transform.position += Vector3.left * speed * Time.deltaTime;
         }
         if ((Input.GetKey(KeyCode.RightArrow))||(Input.GetKey("d")))
         {
             transform.position += Vector3.right * speed * Time.deltaTime;
         }
         if ((Input.GetKey(KeyCode.UpArrow))||(Input.GetKey("w")))
         {
             transform.position += Vector3.up * speed * Time.deltaTime;
         }
         if ((Input.GetKey(KeyCode.DownArrow))||(Input.GetKey("s")))
         {
             transform.position += Vector3.down * speed * Time.deltaTime;
         }
     }
 }```
#

that's it

#

@high night

high night
#

print isLocalPlayer at start

rancid anvil
#

okay

high night
#

see if you get two true's

rancid anvil
#

Nope , it's right

#

@high night

high night
#

hm

#

you shouldn't be seeing rotation on other character
@rancid anvil

#

Other body should stand still

rancid anvil
#

but i see it

#

@high night

jade glacier
#

You have an is local player test after if(!islocalplayer) return

rancid anvil
#

yes

jade glacier
#

...

rancid anvil
#

I know lol but even if I leave it

#

it wont work

stuck hinge
#

network transform has Client authority ?

#

if there is one im assuming theres one

#

hang on I need to read the issue mor

#

camera.Main

rancid anvil
#

@stuck hinge

stuck hinge
#

are you sure you using each characters own camera?

jade glacier
#

I would personally not use isLocalPlayer regardless. This isn't what it means hasAuthority is preferred.

stuck hinge
#

HasAuthority is what I use

#

But @rancid anvil please check that you are not using the wrong Camera.main

rancid anvil
#

Alright let me try with HasAutority

#

But @rancid anvil please check that you are not using the wrong Camera.main
@stuck hinge How?

stuck hinge
#

are you having issues with both client and server ? or one

#

I was making an RTS and ran into similar issues

rancid anvil
#

if(HasAuthority){
rb.transform.rotation = Quaternion.Euler(0f, 0f, rotation_z + offset);
}

jade glacier
#

Does it all work locally when you remove the authority checks?

rancid anvil
#

If i try with hasAutority , only the main player rotate

#

i mean only the player that host

stuck hinge
#

can you stream ?

#

unity3d?

rancid anvil
#

Wait

#

go dm

#

2d

jade glacier
#

Are you using Network Transform to sync it?

high night
#

Do you usually have a int number on server and updated by server that keeps the time?
(This number is also sent to clients with states, clients wil figureout their times based on this value)

Or do you use the networked time? (which is synced time on servers and client, synced from the start)

Just wondering

#

.
When the server lags, does the server have to catch up?

#

Or time is just stopped/slowed for a while

#

I think the second one is more logical

jade glacier
#

Using time with networking isn't really a very good practice for a lot of reasons.

high night
#

you mean the synced time?

jade glacier
#

You typically do everything based around a fixed tick, and all timings based around those ticks.

high night
#

by time i mean frame number

#

//5 is tick number

jade glacier
#

I would try to use that term then, since they have very different names and meanings

high night
#

okay, how about how the ticks/frames number is handled though?

#

What happens when the server lags

jade glacier
#

you should also be very clear what you mean by lag

#

because in this context lag can mean like 3 different things

high night
#

(server can't simulate fast enough)
Does server constantly try to catch up?

jade glacier
#

If the server can't simulate fast enough, your game is broken and you need to go refactor it until there is no risk of that.

high night
#

So i shouldn't deal with this case?

jade glacier
#

The server doesn't do anything on its own, but FixedUpdate will play catchup if that is your timing segment

#

If the server hangs, simulations will stop happening and clients will buffer underrun waiting

high night
#

if server runs 1 frame per second
when i look at 1000th second, server will always have simulated 1000 frames right?

#

even though server was overwelmed in 200th second for example (cant simulate fast enough situation)

jade glacier
#

Depends what is triggering your simulate code, but I would assume you are coding for it to work like FixedUpdate, or to just use FixedUpdate

high night
#

I control it in Coroutine

#

at 50 hz

#

i have this:

int FrameNo(): 
  return (int)(Mirror.NetworkTime.time / 0.02);

while(true):
  SimulateUntil(FrameNo())

  Wait(0.02f);

Think of it like this

#

frameNo : (int)(Mirror.NetworkTime.time / 0.02);

#

So always same number of frames simulated at sime time

#

If server can't catch up, it freezes

#

Because "Mirror.NetworkTime.time" doesn't ever stop

jade glacier
#

I personally always just use a net tick singleton, and tie everything to FixedUpdate. Coroutines are satan's work.

high night
#

other option

int frameNo;

while(true):
  SimulateUntil(FrameNo())
  frameNo++;
  Wait(0.02f);

And i sync the frameNo to clients

#

.
@jade glacier If you fix timesteps, FixedUpdate may get you in trouble though right?
But if you don't sync it, then your server may freeeze

#

By default, fixed update interval can get big as 0.33f, whereas it's 0.02f normally

#

It does help catching up at the cost of ruining your fragile determinism

jade glacier
#

Why would fixed get you in trouble?

high night
#

Because of state syncronization
I'm not doing the snapshot interpolation

jade glacier
#

Fixed is Unity's fully built in fixed time engine, and it also will ensure that your net code works on the same timings as the physics engine

#

You have a tick, so you are doing snapshots

high night
#

I need my time intervals fixed

jade glacier
#

whether you interpolate or extrapolate, or neither is separate

grave coral
#

what is better, to have the client ask a question to the server, and the client acting on the request, or having the client call the server, and then trigger a RPC (from the server) ?

jade glacier
#

The honest answer is that that is all pretty terrible.

#

adhoc messaging creates horrific tangled race conditions. You want to reduce your game to a tick based simulation, and tick based user inputs. Once your game runs in that context, then everything is a question if whether your a syncing a buffered input, or a buffered state.

grave coral
#

it's turn based though

jade glacier
#

Though to your question, what you are asking about is prediction. If the client acts locally on something that it needs server permission to do, you just have to have a way of cleaning things up if the server doesn't give the answer you expected.

grave coral
#

so basically the client would send a moveIntention to the server

#

and the server would return a bool

jade glacier
#

Turn-based is still tick based... those ticks just don't happen at a fixed rate.

grave coral
#

but I was wondering if I should use an RPC instead

#

which seems worst to me

jade glacier
#

Typically you give the user feedback that their command has happened... like a sound and like a cursor ding on the ground where they clicked or something.... and then you wait for the confirmation before actually simulating forward.

#

RPCs are just messages, which all networking is. The RPC part doesn't matter.

#

If its turn based, why do you need server permission?

grave coral
#

so that the server is authoritative

jade glacier
#

You are making a non-deterministic turn based game? Any reason you are opting to not make it deterministic?

grave coral
#

what do you mean by non-deterministic?

#

@jade glacier

#

it should be deterministic afaik

#

the server-side stuff is fully deterministic, and the client asks the server for stuff, so it should be

#

a framework I will probably be using might implement async/callbacks for commands toward the server

jade glacier
#

if its deterministic, then your networking for each tick should only need to be a reliable message if the players inputs they applied locally for that tick.

#

And no need to wait for server confirmation of anything, since there can't be any disagreement.

grave coral
#

@jade glacier you don't trust players that's the thing

jade glacier
#

Nothing to trust, its deterministic

#

they aren't sending states, they are sending inputs only. Same as with server auth.

grave coral
#

yeah but the client can't know if the input is ok

jade glacier
#

The difference being that you don't have to transfer states, because its pointless.

grave coral
#

since it dosen't know game state

jade glacier
#

Of course it knows the game state

grave coral
#

nah client is only UI

jade glacier
#

You might want to read up on what determinism means in games, because I think we are having to different conversations.

grave coral
#

yeah I guess

jade glacier
#

There are only two things to sync in networking... inputs, and states.

grave coral
#

I mean it depends on the gameState what effect an input will have

jade glacier
#

The reason for state transfer is because of non-determinism. You have to sync the RESULT of a simulation, rather than just what goes into the simulation.

#

Determinism means that every machine everywhere will produce the same exact results given the same previous state and new inputs.

#

So to get in sync, you just need an initial state transfer, or to be sure each client has the full history of user inputs.

#

Once you are in sync, you are forever in sync.

grave coral
#

still don't get where it's not deterministic

#

but anyways it will have to be RPCs anyways

jade glacier
#

where what is not deterministic?

grave coral
#

so I will have to change it so the client dosen't wait for anything

jade glacier
#

RPCs are fine, though bloated unless you are RPCing a byte[]

grave coral
#

since it affects other clients

jade glacier
#

You said turn based... but now you are describing realtime

grave coral
#

I know for a fact I am not

jade glacier
#

turnbased you can lockstep fully. Realtime you need an intermediary like a server to be the final word on what inputs were.

grave coral
#

so the entire game logic runs on the server

#

and the client dosen't need to know how the game works, it just displays it

jade glacier
#

yeah, we are kind of going in circles here. Give it a shot how you want to.

#

Just I would recommend reading up on the concepts of determinism, and the benefits

grave coral
#

I mean I don't get what you're saying

jade glacier
#

the big one being that you don't need to do any state transfers

grave coral
#

I know how determinism works in a state machine

#

the backend is deterministic and I don't see why you asume it is not

jade glacier
#

In networking... all traffic related to game simulation is either Inputs (Cause) or States (results)

#

with determinism you can eliminate the need to transfer states

grave coral
#

you're saying an input is a state?

#

all that's being transfered is a direction and an ID

jade glacier
#

nope, an input is the non-deterministic stuff you put into the simulation. The previous state is the starting point... the inputs create changes to the state... and a new state is produced.

#

what an input is, is up to you... but it is the stuff the users do... be it key presses, or mouse moves, or whatever....

#

The state is the end result values of your game after the simulation runs... like player locations, health, velocities... etc

grave coral
#

yup, and every position on the board is mapped, so from a starting position the resulting position from a given direction is always the same

#

legit you could strictly compare the directions and the resulting arrays and the result will be the same

jade glacier
#

Then that would be determinsim, and you can make that work for you. You don't need to worry about security, players can't cheat determinism. If they do something illegal (by hacking) it will just cause a desync and that will pretty much end the game

#

Typically that would produce a checksum failure... which means its over.

grave coral
#

yeah so that's great, but right now my issue is that players have to have a limited time for their turn

#

but I can't really do that from the server, because of latency

jade glacier
#

An intermediary likely is needed for that yeah.

#

The server can do that, but you will need the clients to produce heartbeat ticks of some kind.

grave coral
#

but the issue is that you could cheat an heartbeat tick for example

#

since it's all local

#

no?

jade glacier
#

For that scenerio, you will need a master intermediary like the server to be the final word on inputs.

grave coral
#

my first idea was to have the timer locally, but you can cheat that pretty easily also, not that I should worry too much about it but kinda sucks to have everything authoritative except that

jade glacier
#

yeah, you will need a 3rd party authority on that. And you will need the means to rewind and resim if the server says your input didn't make it in time.

#

Depending how aggressive you want to get with it, you can also have the other client monitor its ticks, or you can have the server just loosely check for excessive heartbeat holdups... and if they do it too much kick them and give the win to the other player.

grave coral
#

so you get heartbeat ticks, and check if they respect a certain thresholds, and also have some sort of timestamp on each of them, including the turn start and turn end server calls?

jade glacier
#

I would probably break down a turn into X heartbeat packets. And the server/other player can raise a flag if they get held up in a way that seems unfair.

grave coral
#

ohh, interesting

jade glacier
#

no need for timestamps, you should be on a fixed tick

grave coral
#

how do I know that I'm on a fixed tick?

jade glacier
#

Because if you aren't you should be.

grave coral
#

I mean, I didn't create my own networking library

jade glacier
#

Fixed ticks = sanity. Adhoc time = hell in networking.

#

Fixed tick is as simple as using FixedUpdate for your timings rather than Update

grave coral
#

true

#

really expected to find a more elegant solution

#

seems messy but I guess if it works

jade glacier
#

Queing up the players actions and sending them every tick is pretty elegant.

#

Its as clean or dirty as your simulation is.

#

you can send it all on one tick, and just keep an eye on the elapsed time, and terminate the game if they exceed a tolerance.

grave coral
#

I guess I could also just do it locally for now until problem arise, since the code that needs to be added will be the same either ways

#

hmm

#

I didnt know it was about sending the info at the same time as the heartbeat

jade glacier
#

I would solve that problem later. Getting your simulation broken down into ticks, inputs and states will make the rest easy to solve.

grave coral
#

though you would just monitor them and know if it was before or after the 'timer number of heartbeats' threshold

jade glacier
#

The value of the intermediary ticks is you might want the other player to see what the player is doing, rather than getting it all after the fact.

#

Like in Hearthstone you can loosely see the other players actions.

grave coral
#

loosely as in it's out of sync?

jade glacier
#

Its still in sync, its just giving the other player X ticks worth of turn. I have no clue, I don't even know what your game is - so the best answer is totally based on what you are trying to do.

#

Hearthstone is loosely because its not determinstically locked second by second. Its deterministic because everything happens on action at a time.

#

You won't see things perfectly time aligned with the other players actions, but you will see that players actions in the correct order.

grave coral
#

ohh and you sure thats how it works in HS?

jade glacier
#

HS I believe is server based

grave coral
#

so the player sends packets every X tick?

jade glacier
#

for all the random shit

#

leaving the random generation on the clients would open the door for cheating, since you could determine the outcomes of actions before you do them.

#

I was only referring to HS for the way you see the other player acting during their turn

grave coral
#

yeah, still trying to wrap my head around the heartbeat thing though,

jade glacier
#

just think of it as sub-turns

#

give a player X ticks for their turn, and any inputs made you queue... and then apply them to your sim locally when the next sim tick happens. And send those exact same inputs to the other players, along with the tick ID.

#

It basically is treating it more like a realtime game, but its a slower paced lockstep.

#

Though again, I have no clue WHAT your game is or what kind of tick rate it would need/want.

#

deferment is pretty important. Don't just go applying inputs directly to things in Update()

#

use the space between ticks to collect (queue) user inputs, and apply them on the simulation tick in order.

Then if you send those same exact inputs to other machines, they can reproduce the sim step exactly the same. That is the principle of determinism.

grave coral
#

What about getting the player's ping for example

#

And calculating the time equal to given time + player's ping x 2

jade glacier
#

you could factor that into the forgiveness sure. Though of course they could fake that.

#

Keep in mind ping won't matter

#

But you can certainly add it into the forgiveness.

grave coral
#

ping wont matter?

jade glacier
#

I would REALLY not start your focus on this part. Focus on your simulation and boiling your game down into ticks.

#

Forget a said anything about ping. Its so far away from the things you need to be working on.

grave coral
#

yeah thing is, the only aspect of the game that requires real time is... time..

#

the game could basically run on a REST API

jade glacier
#

Until you have an input/state tick based simulation, this is all pointless conversation really.

#

The highway of network games is littered with guys in these channels worrying about hacking, and this kind of stuff way too soon.

grave coral
#

yeah just seems overkill to get that deep for just time, I guess it is pretty core but taking me far away from the idea of a small networking project I would like to finish

jade glacier
#

Focus on the simulation. THAT is networking, not the messaging.

grave coral
#

I mean the simulation is complete, what do you mean?

jade glacier
#

is it, its purely input/state based on a fixed numbered tick?

grave coral
#

no I guess, but it's not tick based either, it's turn based

jade glacier
#

Is it a pure tick then, no watching the other guy play to deal with?

#

if its like chess, then you may be done yeah.

grave coral
#

yeah you could say that

#

but how do they handle turn lengths in speed chess for example

#

that's the annoying part

#

but yeah, I'm overthinking it I guess

#

could just do that locally and not worry about theses things till they happen

jade glacier
#

So no need for the intermediary ticks. I would just make your intermediary server do some basic time accounting to check for time cheating.. and if it spots it kick the player and award the win to the other guy.

grave coral
#

how do you do basic time accounting?

jade glacier
#

When the player is sent the other players turn, log the time on the relay/server

#

and compare that with the time the player returns control. If that exceeds the turn length by too much too often... call the match.

#

The alternative is to enforce it by making all actions need to be confirmed by the server.

grave coral
#

yeah alright, that I can do

#

the 1st

#

πŸ˜›

jade glacier
#

Which it sounded like you didn't want to do.

grave coral
#

I mean, all actions are already confirmed by the server

#

that's the thing

jade glacier
#

That route you have two choices... to predict and rewind if the server says you were too late... or just to delay the inputs until the server confirms.

#

The issue is prediction

grave coral
#

It's as simple as you skipped your turn

jade glacier
#

But if the player on their side acted in time and you allow that to predict, you will have to undo that action.

grave coral
#

so you wont see anything moving, since nothing moves until the servers says it did, and the server wont move anything

jade glacier
#

Then you already are doing full server auth yeah

grave coral
#

yup, but with time it sucks

jade glacier
#

You can do what you are describing there and still be deterministic, so that's all fine

#

the downside is players will feel the latency in their actions.

grave coral
#

yeah, well I want to add some local feedback to say that you did that move, and then the server feedback

#

but yeah I know that there will be that feeling

jade glacier
#

yeah, that is a perfectly acceptable method

#

and is pretty common

grave coral
#

but with time it's never perfect, is it

#

what we were talking about earlier is non authoritative time

jade glacier
#

The server knows the real time. All you are doing is waiting for permission for each action

#

The client will be able to have a reasonably good guess on the hourglass based on ping.

grave coral
#

yeah but the ping makes it so there's a delay

#

but I guess the server could do like u said and check if the client is cheating

jade glacier
#

There is no cheating in this case really

#

the clients actions after the server says times up will just get a denied response.

grave coral
#

and I probably add the player's ping * 2

#

to that

#

or average player's ping rather

#

otherwise if a turn is 1 second

#

he could get a real 8th of a second to react

#

with a 100ms ping

jade glacier
#

or half RTT

grave coral
#

RTT?

jade glacier
#

ping

grave coral
#

why half?

jade glacier
#

That's how long it took for the server "your turn" message to arrive

grave coral
#

oh right, it's half

jade glacier
#

its all pretty easy math, just use the right value for the thing you are trying to solve for

grave coral
#

so one player's ping accounts for receive time on both side

jade glacier
#

its all super loose, since that is just to try to give the player a guess at a turn timer

#

You don't generally get a ping between clients, nor need one.

grave coral
#

yeah, they will see stuff moving but they are independent

jade glacier
#

the players only concern is how long it takes to get a message from the server, so it can guess the turn time left. Other than that there is no time concerns at all.

grave coral
#

yeah, still wanted to have it more accurate than that

#

but I guess it's as close as it gets

jade glacier
#

The server will just stop accepting inputs when its clock says the turn is over.

grave coral
#

without going into ticks

jade glacier
#

The ticks aren't needed if you aren't doing any kind of player observation stuff

grave coral
#

yeah here you go

#

but server timer is never a real timer, so it would have to be local

#

then u need player observation

jade glacier
#

If you have a server of any kind, I would make that server the god of time.

#

player observation I mean like hearthstone.. where you can see the other player doing stuff.

grave coral
#

but lets say u want to display that server god time

#

u can't

#

cause ur the client

jade glacier
#

rather than old Civilization... where you just get their turn when they are done.

#

You can't ever have networked time in networking, unless you are like fully extrapolated determinism. There is no need for it anyway.

#

Your ONLY use for time in this case is the client needs to know how long they have left in their turn, so that is something of a guess based on RTT

grave coral
#

alright

#

I will go for that

#

thanks a lot

#

more complicated of a subject than I expected

#

the rest should be easy though

jade glacier
#

All you need locally for that is when the server packet saying "Your Turn" arrives... you subtract half RTT from that to get the current remaining time.

#

It will likely be a bit off, but by a bit I mean like a ~10ms off

grave coral
#

ye, or let the server do the math, and the client can assume his turn is of the given length

jade glacier
#

there is no way to know what internet jitter is

grave coral
#

yeah it's fine tbh

#

like even 50ms variance is prolly fine

jade glacier
#

If their connect is complete dogshit... that is on them

grave coral
#

yeah and then u can prolly just drop them from the game

#

or display something idk

jade glacier
#

Or they will just be annoyed that the turn end clock isn't always honest

#

HS has horrific turn clocks... doesn't stop them

grave coral
#

warning the clock might not be accurate cause ur internet is dogshit

#

yeah lets just say when you have only 1 sec to play with vs 1 min

#

it matters more πŸ˜›

jade glacier
#

Or just make the bar lie and promise less time than there actually is.

#

like say turns are 30 secs but make them 35 secs

grave coral
#

yeah I guess not showing an actual number is better too

#

like in hearthstone they use the bomb thing

jade glacier
#

yeah, just make it and see... adjust creatively

grave coral
#

so it can be off and u don't really realize

#

aight well thanks again!

#

well fuck, that's a way to do it

jade glacier
#

yeah, RTT comes from the transport

#

and I think they do a smoothing on it, so its not too noisy

grave coral
#

yeah seems like it

#

so I can just display that and it should give a good idea

jade glacier
#

NetworkTime I disklike, but you can use it here - its just RTT wrapped in their own attempt to make things transparent. Its pointless though for you.

grave coral
#

ohh right

jade glacier
#

You don't need a universal time, you need time until turn ends. So just TurnLength - RTT * .5f

grave coral
#

yeah I guess I can just do it myself

#
  • .5f is the smoothing?
jade glacier
#

its 1/2

grave coral
#

ohh right

#

lol

jade glacier
#

just a good practice to always multiply rather than divide in programming

#

since its faster

grave coral
#

never heard that

jade glacier
#

doesn't matter here. Its more for hotpaths

grave coral
#

I mean, good to know though!

empty quiver
#

is this the right place to ask about NetCode? or should those questions go in #archived-dots ?

jade glacier
#

Dots will likely get you more answers

empty quiver
#

ok

crystal ore
#

Hi, does anyone know where to start if I wanted to write a multiplayer game in unity? I have unity/general programming experience but the network stuff really confuses me--all the tutorials I've found use something that's being deprecated apparently, so I'm not sure where to start

high night
#

@crystal ore photon is common and mirror is unet's successor

#

I'd choose either mirror and photon
using mirror currently though
used some photon before

crystal ore
#

Ok great, thanks!

rich flame
#

Im trying to learn photon after using unet for a while, diffrences are there

grave coral
#

Should I use a different enum to represent a movementIntention (frontend to backend) from a movementDirection (backend to frontend) if they are the same?

jade glacier
#

Not sure what front and back end are in the context of your question. You are trying to make a non-unity build for the server in a different language or something?

grave coral
#

Framework is a bit weird, ended up just using the same for both, since they represent the same thing, they don't need to represent the context/use case aswell

#

Anyone has recommendations when it comes to login for Unity, and storing data, though of maybe using a REST API to do that

crude night
jade glacier
#

to get off to an easy start, I would just make my net rate and my sim rate match

crude night
#

I do not understand

jade glacier
#

Do you have a simulation? Where/how are you generating your ticks?

#

If your sim is fixedupdate... generate a tick every fixedupdate.

crude night
#

wait can i show you a simple MonoBehavior class with only the tick to get a correct opinion?

#

at least you can tell me if i am wrong

jade glacier
#

never hurts to paste it, someone else might have an opinion as well

crude night
#
public class NetworkClient : MonoBehaviour
    {
        // frame count
        readonly int frameRate = 60;
        int frameCountPerSeconds = 0;
        int frameCount = 0;

        // tick
        readonly int tickRate = 20;
        int tickCountPerSeconds = 0;
        int tickNextCount = 0;
        int tickCount = 0;

        void Awake()
        {
            Application.targetFrameRate = 60;
            Application.runInBackground = true;
        }

        // Start is called before the first frame update
        void Start()
        {
            StartCoroutine(LoopWaitForOneSecond());
        }

        // Update is called once per frame
        void Update()
        {
            frameCount++;
            
            // frame rate => 60 / tick rate => 20 = 3   // |frame|tick|result|
            int divideRate = (frameRate / tickRate);    // |  60 / 20 | =  3 |

            // tickNextCount = 1|2|3
            if (tickNextCount < divideRate)
            {
                tickNextCount++;
            }

            // tickNextCount max length from tickEvery
            if (tickNextCount < divideRate) // != or <
            {
                return;
            }

            tickNextCount = 0;
            tickCount++;

            // update 20 tick per seconds
        }

        void OnGUI()
        {
            GUI.Label(new Rect(10, 10, 400, 50), string.Format("frame per seconds: {0}", frameCountPerSeconds));
            GUI.Label(new Rect(10, 35, 400, 50), string.Format("tick per seconds: {0}", tickCountPerSeconds));
        }

        IEnumerator LoopWaitForOneSecond()
        {
            while (true)
            {
                yield return new WaitForSeconds(1f);

                frameCountPerSeconds = frameCount;
                frameCount = 0;

                tickCountPerSeconds = tickCount;
                tickCount = 0;
            }
        }
    }
#

with this I allow the client to send 200 snapshots per second

#

is the right way?

harsh dew
#

Why would the client send snapshots?

crude night
#

I find it very difficult to understand English for me when the client sends an input I take its as a snapshot?

#

translations also don't translate very well 😦

jade glacier
#

you should use like hatebin.com for larger code posts like that, easier to read. And if posting here be sure to include the ```cs at the top so it formats it better.

crude night
#

I added the ``

jade glacier
#

There is a lot going on there that I would not do. First thing being the use of a coroutine.

#

```cs
your code
```
the cs adds the colors

crude night
#

why not use it?

#

ah ok thanks for the cs

jade glacier
#

I'm not going to go into that discussion, there is plenty online about why coroutines are a nightmare if you google the topic.

#

Are you doing your own simulation, or are you going to use PhysX?

crude night
#

PhysX?

jade glacier
#

Have you made a Unity game before?

crude night
#

complete no I have experienced the basics

jade glacier
#

PhysX is the physics engine. All of the colliders, rigidbodies, etc... have you used those?

crude night
#

yes

jade glacier
#

That is PhysX

#

is your new game going to use those, or are you making your own simulation?

crude night
#

I think to use it for the moment for simplicity

jade glacier
#

Then your simulation is PhysX

#

which means your simulation timing is FixedUpdate

#

That is your simulation tick

crude night
#

I don't understand very sorry
the simulation of the player I have to put it in the fixed update? is that what I should understand?

jade glacier
#

Do you know what simulation means I think is the first question?

crude night
#

the simulation is the movement simulated by the player's keys

#

I may have simulated them not executed it is it?

jade glacier
#

The language barrier is making this harder than it needs to be I am sure.

crude night
#

I think I understand better the player sends it is input and predicts its change it can be executed while waiting for the response from the server

then on the server side, he simulates the world in his time

#

it's correct ?

jade glacier
#

It is so much more complex than I can explain here, especially with the language barrier. I don't think I can help sorry.

crude night
#

😦

#

someone can at least tell me clearly the steps that a server and a client must each perform in turn

near cairn
#

ok so let me explain what is going on, as you can see in the window of the left player, at the down right corner it says CLNT-UN:username this stands for client username: username. for some reason even though it shows up as username in the left client's window, the nickname shows up as player(clone) on the right player's window. ill send everything responsible for setting up the usernames right now:

Start():
pv.RPC ("setNick", RpcTarget.AllBuffered, gameObject.name);

[RPC]
setNick(string nick):
usernameTXT.GetComponent<Text> ().text = nick;

also the there is a function for teams, which also didnt work, but i assume that it originates from the same issue as the nickname problem.

#

@crude night elaborate on the server and client must each perform in turn

#

oh hold up....

#

nope still have no idea

#

i didnt receive them before this problem started

stiff ridge
near cairn
#

is it that hard to tell me the solution though

stiff ridge
#

The second screenshot you shared shows you didn't connect (or at least didn't finish connecting).

near cairn
#

i switched unity versions from 2k17 to 2k18 and this error started appearing

stiff ridge
#

The solution is written in that tutorial. And it will help you know the context, unlike any short info you get here.

near cairn
#

what do you mean by down

#

what down exactly

stiff ridge
#

Sorry. Bad translation from German thinking. Removed that "down"

near cairn
#

i know everything mentioned in that tutorial

#

nothing there helped me really

#

@stiff ridge do you know the solution to my problem and just playing with me or you do not know the solution and sending me to an introduction tutorial

jade glacier
#

To get any help on that, you would need to give a lot more context. Otherwise everyone can only say "You have a bug in your code somewhere"

near cairn
#

well i don't know what else to say really

jade glacier
#

That you are getting warnings saying you aren't connected, would suggest you are trying to call these things before you are in a room.

near cairn
#

but the thing is that when i used 2017 it was all fine and everything was syncronized across the network

#

i switched to 2018 and everything was gone to spaghetti

jade glacier
#

Execution order changed on you maybe, and your code timings were fragile and not specific enough maybe... dunno.

#

That literally is giving no information on where things are going wrong. All we know is you are getting a message saying you aren't connected when you try to do something....

near cairn
#

i don't know much myself

jade glacier
#

So all we can say is "Make sure you are connected before that calls"

stiff ridge
#

Use the SupportLogger to get some context into the console log. Post the complete log.

near cairn
#

all i know is what i typed above

jade glacier
#

Post complete code as well. Very short snippets give no context for what callback you are calling things from, so we have no idea what your timings are.

#

Like if you are calling networking stuff in Start(), that is risky.

near cairn
#

alright

#

what was that site for posting code

#

you sent it here once

jade glacier
near cairn
#

alright thanks

#

actually i think it will fit here

#
void Start () 
    {
        pv = GetComponent<PhotonView> ();
        rb = GetComponent<Rigidbody> ();

        pv.RPC ("setNick", RpcTarget.AllBuffered, gameObject.name);
        pv.RPC ("sendColor", RpcTarget.AllBuffered, chosenTeam);
}

[PunRPC]
    void sendColor(int clr){
        mesh.GetComponent<MeshRenderer> ().material.color = teamColors[clr];
    }
[PunRPC]
    void setNick(string nick){
        usernameTXT.GetComponent<Text> ().text = nick;
    }
#

this is the one that should set the nickname and the colors

#

ill now send the script which connects the client

jade glacier
#

Yeah, don't use Start() for networking would be the first thing

near cairn
#

hmm

jade glacier
#

That is not a network aware timing, so all bets are off.

#

Use the PUNCallbacks for your timings

near cairn
#

that can explain alot

#

MonoBehaviourPunCallbacks you mean

#

?

jade glacier
#

Probably, I don't keep exact names in my head

#

vs hints code for a reason πŸ˜›

near cairn
#

so i replace MonoBehaviour with MonoBehaviourPunCallbacks

#

was that the problem?

jade glacier
#

You really need to refer to the docs for that stuff

#

I can't code and read the docs for and with peeps in the channels, or I would never get any work done.

#

I can just point you in a direction

stiff ridge
#

Even if you had a running game, I can only suggest to do the tutorial.
It will (also) show you how to use the built-in nickname for players, so you don't have to send RPCs for that in the first place.

near cairn
#

i dont like this built in stuff

#

it's optional in my case

#

so i prefer doing it on my own

jade glacier
#

Then you are basically wanting to be out on your own... so you are going to have to get your hands dirty in the docs

near cairn
#

to also tweak specific stuff i want in my own code

#

as i said it worked fine in 2017 @jade glacier

#

and i nailed the nickaname system fast

jade glacier
#

Because you coded in a race condition using that Start() maybe... who knows

#

Building out to mobile or different exe targets also might have exposed the problem. But again. No clue.

near cairn
#

well ill try what you recommended

left cobalt
#

Is it possible to send 5mb image over network? Im using photon.

gleaming prawn
#

Not meant for that purpose

jade glacier
#

Good lord no

#

Keep your assets like that someplace "webby" and just reference them by link or something

#

realtime game servers and file hosting you don't want to go mixing.

gleaming prawn
#

Realtime game servers are for sending high frequency (20, 30, 60 Hz and up) very small packets ( < 1KB so for in one UDP datagram) efficiently...

#

A photon server can hold a few thousands game clients with this kind of message passing...

#

Sending images is normally done over TCP, via a CDN infrastructure... So two different problems

high night
#

Is there some app that emits my packets from a public ip from some other server?
So i can access there behind my NAT
and host the game with that servers public ip?

gleaming prawn
#

You meet stun punch through, or upnp (and because these only work 85% of the time, a relay service as a fallback)

#

Need*

high night
#

What i'm describing is more of a relay server no?

gleaming prawn
#

So, steam does that for you, photon as well (low level realtime gives you punch as well)

#

Yes, but you want to avoid the relay if possible

#

Punch through enables direct connections via NAT

#

That's standard practice for client hosted listen servers

#

Photon bolt comes with that, etc

high night
#

Does photon include NAT-punchthough-ed connections in it's CCU?

gleaming prawn
#

Depends...

#

In bolt yes, because you are using the service for matchmaking, signaling of the punch and fallback

#

For low level realtime it gives you the socket, so I think if you disconnect from the room when a punch works it stops being a ccu

#

But you need to read the EULA

jade glacier
#

As well as just paying for having that library made for you - I assume is baked into the hosting costs a bit? For Bolt?

gleaming prawn
#

It's our software library that you are still using.

jade glacier
#

just answered πŸ™‚

gleaming prawn
#

Yes

#

It's our daily job to create these libraries so you don't have to...:)

#

Or you don't have to pay a few k $ a month for someone to do for you (+ hosting)

#

Steam does for "free", assuming 30% of your revenue is free...

high night
#

Well, i'm pretty much just a hobbyist, i haven't been digging much into the costs, revenue and how will it recoup the costs
I'll worry about those if i can make a decent game

gleaming prawn
#

And does with just a basic transport, no actual netcode... Just a comparison

#

Photon you pay 95 buck ONCE for 5 years of 100 ccu

#

You need a game with a decent amount of players to passa that threshold

#

Oketjing like 40k Mau

#

Something*

high night
#

so these 100 ccu will be only the non punchtrough users? %15 of my users?

gleaming prawn
#

Not in bolt

#

Bolt is always connected to the room, so everyone is CCU

#

I do not know about the photon realtime (low level) EULA

#

But as I said, probably all are CCU

#

That is how we pay for the employees... We done pay only for servers

#

You know, these boring guys who write the libs (like you)

#

:)

high night
#

No, lol i won't be writing libs

gleaming prawn
#

If you want to write games, it's what emotitron says

#

Use bolt, or quantum, or mirror

#

Not sure if mirror has punch + relay though

high night
#

I am just writing netcode for my game
I won't be writing networking layer stuff

gleaming prawn
#

You can even start with the free 20 CCU tier with bolt

high night
#

I just make the bytestreams

gleaming prawn
#

Etcode IS what we write

#

Netcode

#

Bolt it is, I mean

jade glacier
#

Mirror has some punch stuff now, not sure about relay. But I think they are charging for those services like everyone else. Since no one wants to pay for your networking costs.

gleaming prawn
#

Or quantum, it replaces your netcode (I won't get into details)

high night
#

I enjoy writing netcode,
And i want to try funky things after my system is stable

gleaming prawn
#

Yeah, I follow your discussions

#

It's fun to do it

jade glacier
#

If you are a hobbyist just host a server on your local dev machine and open a port.

#

If you actually intend to have players, you are going to eat some costs though.

gleaming prawn
#

Yeah, you can reverse nat

#

Port mapping on your router

#

Manually

#

Upnp is for doing that automatically, but super unreliable

jade glacier
#

Your ISP might come down on you for that as well if you actually get real users

gleaming prawn
#

And not safe,.lol

jade glacier
#

But once you are starting to take those things into consideration, you might want to rethink if you are a hobbyist.

high night
#

I think send rates are very slow from my router to world if you know what i mean

#

upstream i think what networking guys call it

#

the upload speed i mean compared to download

gleaming prawn
#

But bandwidth should be ok

#

Unless your netcode is really bad

#

Nd of course, depends on what you want to do

#

You won't host more than 16/20 players, will you?

high night
#

yeah right i wont

gleaming prawn
#

In that case, consider the photon realtime as a fallback

#

Because 20 CCU is free anyway

#

Ithout asking for 30% revenue

#

Without

#

But o would not use relay 100% of the time it doubles the hops

#

Adds delay on a listen server architecture, should be just fallback, really

#

For quantum, the photon server is the host/server so then fine

high night
#

quantum servers can have dedicated servers?

gleaming prawn
#

Quantum is different

#

Yes, we can give dedicated servers, including running authoritative SIm on them

#

But it's a different architecture

#

Quantum is a game engine

#

We don't run unity on servers

#

So we have our own physics, path finding, math, ai sdk, etc

high night
#

hmm, interesting

gleaming prawn
#

It's not FPS style netcode

#

Like bolt or CS, or the new unity netcode

#

It's deterministic predict rollback

#

With server mediation

#

You do not deal with netcode, just gameplay

#

And unfortunately not aiming hobbyists

#

At least not yet

#

Not that you are a bad hobbyist

#

Just that it does not have a free version

#

We give free trials, and some rev share options for really good groups/studios

#

But it needs to be something more seriously targeting business results...

jade glacier
#

Exit is a small number of people, so the support of free stuff for hobbyists isn't REALLY a winning strategy.

#

Every minute in a channel explaining something is a minute not coding.

gleaming prawn
#

Yep,.we do not have investors to burn from,.lol. not anymore, company is past these days log ago

#

Just a small profitable business.

jade glacier
#

That being said, being friendly to hobbyists is good in that some % of those hobbyists turn pro.

gleaming prawn
#

With some cool customers

#

Well, I enjljoy.beingnhere, even though I should be sleeping

jade glacier
#

But spending 2 hours explaining to someone in chat why their gameobject isn't syncing movement.... hurts a lot πŸ™‚

#

Yeah, I do this because its a break from thinking, but it can get time consuming.

gleaming prawn
#

Yeah, for quantum we have our own private discord

#

About 400 Devs in there alread...;)

jade glacier
#

That is the nice thing, once you have devs, they support one another

gleaming prawn
#

Yep... And it's been a surprise how some big shot studios are friendly and participative

#

Really good Devs in there, it's fun to watch

high night
#

Well, i dont know how likely i am to turn into a pro.
I don't feel worthy of your pitchπŸ˜…

gleaming prawn
#

I hate to pitch, lol

#

I've just seen the same story so many times

#

You are on a good track, better than 95% or more.of the pack tbh

jade glacier
#

If people are excited about the product, you can't stop them. Programmers love tech talk.

gleaming prawn
#

I like our results, yes, but I do not like to pitch in itself

high night
#

I see, you are fortunate to make a business of your passion

gleaming prawn
#

This is why I always mention the competitors. It's not my intention to divert people

stray scroll
#

Hmm, if I knew quantum were open to rev-share I might've looked more into it more. ^:) How would you resolve persistent data that is the outcome of a match from such a system?

jade glacier
#

You can learn a lot using something like Mirror. There is a benefit in not having the high level stuff, and seeing for yourself where things go off the rails.

gleaming prawn
#

We have cross platform serialization of the full snapshots

#

Turnkey

#

Jaws, super simple....

#

And we can run the master simulation on the server

#

So you can store game results from there

stray scroll
#

Ah, I thought it was server less

jade glacier
#

The server doesn't get brutalized like clients, since it doesn't have to resim constantly.

gleaming prawn
#

It is a isnt

#

There are several ways to do

#

Server is mandatory for input management and time sync , but that is game agnostic

#

And with just that you can already forward full input stream to a backend

#

So you can reproduce game match results from a referee .net.console app

#

Say to audit tournament matchs

#

Matches

#

Optionally, you can just reuse the same SIM code and run on the live server, so you.have an authoritative master source even for snapshot based late joins

jade glacier
#

I didn't even consider that. Rather than having the server run the sim and hold that in memory - you can just write each ticks inputs to a file, and have a second machine recreate the end state in one shot off the game server. Nice.

#

file meaning database, bad use of language

gleaming prawn
#

And because we have the whole tooling around the ECS data structures, you don't need.to write serialization code, all cross platform determinist by design

#

We also support grabbing snapshots straight from another client for late joins, also out of the box

#

So it's pretty much a decision you can do later down the line of you start making shit loads.of money with the game

#

To run the server Sims or not to

stray scroll
#

I guess it's not directly compatible with Unity ECS, but you run your own?

gleaming prawn
#

It's our own, production ready, not beta...:)

jade glacier
#

LOL

#

burn

gleaming prawn
#

We are about to launch quantum 2 (hopefully to customers.tomorrow)

#

We want to eventually integrate to unity's ecs (when it is reliable enough)

#

For rendering, animation particles

#

It's nice stuff... We just can't use it at all in its current state

#

And for simulation, nah...

#

Our task system seems to have less "gaps" even... And unity on server would be 10x more expensive... When ours can run on lean .net core

#

As I said, it's fun to benchmark...:)

#

It's cool to demonstrate stuff on a 12 core machine, but in the real world you need to ship games that work reliably on a low end phone with 2 usable cores only

#

Reliably and fast... Of course

stray scroll
#

Hmm yeah. Sounds good ^: ) I just know I can't be paying the 1k$/month as I'm living off half of that/month rn^^

gleaming prawn
#

Fully understand

#

I mean, we have two interesting ways to get hands on it

#

One is, if you and a small group can do crazy cool stuff and have a great idea, we normally pay for well done demos

#

It's a fun way to experiment with, being oaid

#

Second is the rev share deals, also related to a solid plan for something with potential

jade glacier
#

Good way to make a win win with hobbyists, nice call.

gleaming prawn
#

We've been doing this for the past 2.5 Sears with quantum... All samples were created by small studios

#

Years*

#

Win win for everyone, no question.

jade glacier
#

So you are saying I should make my flight model based dueling game πŸ˜›

gleaming prawn
#

The 1k is about the following:

  • the amount of features and tooling and support we give would cost you around 2 devs a month, and take 3 years to make, IF you have good developers (think about a good dev salary)
#

Do the math...:)

#

Maybe @jade glacier

#

So for a professional studio, the 1k is a no brainer

jade glacier
#

Any company with any kind of funding its insane cheap yeah. So the rev share and demo deals kind of fill the gap. You guys have done a nice job positioning.

gleaming prawn
#

I can't mention all, but square Enix Montreal, Ubisoft, moon studios all did the math...:)

stray scroll
#

Yeah sure, but also there are "free* more cumbersome" alternatives, but I understand the logic behind it. πŸ™‚

gleaming prawn
#

Yeah, I'm not here to say people.dontnhave options, as I said, I always mention at least mirror

#

I'm here mostly to hang out and chat with other devs

jade glacier
#

There is something to be said for also not dumping it on the market, because that actually kneecaps the bigger studios with plans and funding. The game markets are already awash in democratized garbage.

gleaming prawn
#

We can't give the same level of support if we had 5k developers in our discord instead of ~400

jade glacier
#

Unity has a dark side.. that being what it has done to online game stores with too much crap.

gleaming prawn
#

Well, do you really care about good netcode? Honest question, lol

#

We deal already with thousands of free users with pun/realtime/bolt

#

But the quantum family is a bit more intense. I usually take things more personally when someone who wrote a game you play relies on you, lol

jade glacier
#

Its pretty obvious the difference. Count the number of published profitable Forge or Mirror-based titles. Having to work out the hard details puts a lot of hobbyist devs in years of endless coding.

#

A complete stack in game networking is massive.

gleaming prawn
#

I know it is massive, photon is small, but just the quantum team count is in 2 digits already

#

Started just fholm and me

stray scroll
#

Asking me? πŸ˜› I care more of the game than netcode x) But I'm considering if I should even consider swapping at this point or not. Already started my game on Unet=>Photon=>Own solution => now NetCode^^x)

gleaming prawn
#

No no, both you and emotitron

#

Question is as a player

jade glacier
#

That would be the endless dev cycle of working with incomplete stacks yeah @stray scroll

gleaming prawn
#

Do you really notice a good netcode when playing

jade glacier
#

I do, but that is partly because I am from a tournament Quake background.

#

Most of what I know about networking I learned having to live with it.

stray scroll
#

shrug somone wrote a review saying netcode for my game was good, made me happy, so guess some care? πŸ˜›

harsh dew
#

You normally notice bad net code

gleaming prawn
#

As a developer quantum has tons of advantages, you finish the game faster, more reliably, with more features available (if you want to give them to players). Besides the obvious super snappy gameplay

jade glacier
#

yeah, that is really more how it works. You notice it when its shit.

gleaming prawn
#

But the later is subtle

jade glacier
#

For most games, the issue is just not getting buried in the endless rabbit hole of net development, which is where most people in these discord channels live.

gleaming prawn
#

But you are full of games with crappy or semi crappy netcode that have tons of olayers

jade glacier
#

I've see many of the same faces working on the same projects now for years in here.

stray scroll
#

I need to sleep on it x) Is there a trial to test out, to see the framework so I could estimate the refactor time? x)

gleaming prawn
#

I mean, look at overwatch, much better netcode than poor pubg and fortnite

#

Yes jaws

#

Send me an email

#

But my point is, pubg had a really bad netcode, specially at the start... 10 ticks per second at the beginning... But didn't matter, right?

#

Lol

jade glacier
#

the BR format was pretty compelling yeah

#

just on its own

#

that and... free

gleaming prawn
#

Here and there you get these unicorns

jade glacier
#

People accept a lot when its free

gleaming prawn
#

Porting to quantum is normally a full re-write.of the gameplay... But Devs who have done it for quite fast acrually

#

Battlelands royale was originally PUN, they re-wrote in quantum in 1 month, then 4 months polishing

#

Nd were talking about a production game with content

#

Ahh, 1 Guy did. The initial port in their team

#

We did a presentation on this last Unite, me and them

stray scroll
#

Aight, will send an email. Now time for some sleep, gngn.

gleaming prawn
#

Since season 7 (now 9), Battlelands runs on quantum

#

N

crude night
#

good evening I am a tutorial that I have a little trouble reproducing on unity to better understand physics and networking
would it be possible to have help on the first part Digital integration
here is the tutorial https://gafferongames.com/post/integration_basics/

native anchor
#

why am I getting this error? Mirror.Weaver error: Cannot generate writer for component type UnityEngine.UI.Text. Use a supported type or provide a custom writer

jade glacier
#

You'll probably get a faster response in the Mirror discord

#

Are you trying to pass Text as an RPC argument?

#

Or you put SyncVar on a Text object?

native anchor
#

oh sorry I thought this was the mirror discord my bad

stray scroll
#

So was thinking a bit about quantum when going to bed and this morning in regards to my use cases. Would I be able to set up a in game lobby(basically lobby world) where players can purchase things for in game money and irl money?

gleaming prawn
#

Normally in-game-asset ownership is handled with a combination of a player profile services + in game mechanisms to enforce the policies

#

Answer is YES, of course, but it's not something you get just out of the box (it's always game specific)

#

As for the lobby you mentioned, this has not to do with Quantum. I'd say

#

Quantum would be for the actual gameplay match... You have the photon room where all game clients must be connected to (in order to start the quantum session - coordinated by the room server plugin).

#

In there you're free to use photon realtime features to communicate anyway between clients (and combine with backend checks via the server plugin - in case you go that more complicated route)

#

So maybe I didn't understand right... If you're talking about an in-game-match items store (like League of Legends'), then that's easily implemented using Quantum's deterministic commands + data assets

#

I'll talk to you over email @stray scroll

stray scroll
#

Hmm I'm talking about having a game world as lobby. I think dungeon defenders does this for reference. So not match lobby but generic lobby.

gleaming prawn
#

Is this your main gameplay

#

It depends on how many players you want to have in there

#

At the same time

#

And what they are doing while in there, what kind of interaction

#

And for the store, how you implement it (as a tightly controlled store with quantum apis, or a separate backend-based store)

#

depends on what it is really.

#

Is it a store for items to use when you "enter the dungeons", metaphorically?

#

Then it'd be backend-based IMHO

#

Quantum is for this:

  • player interaction, specially when you need accuracy, fast pacing, physics, etc
stray scroll
#

Hmm ok, I'll send an mail later more specified :)

gleaming prawn
#

Dungeon Defenders is single palyer, isn't?

#

only local multiplayer

stray scroll
#

2nd one I think I played with this kind of setup

spring crane
#

Both Dungeon Defenders are online multiplayer

gleaming prawn
#

Saw on the Steam page only single player + screen-share

#

Maybe I didn't see it well, let me confirm (not doubting, from the trailer it looks online, yes)

#

Remote play together = streaming...

spring crane
#

Are there VAC enabled singleplayer games? πŸ˜„

#

Not sure why it multiplayer isn't listed there

#

Maybe there is some limit to how many features you can show there πŸ˜„

gleaming prawn
#

yeah, maybe

verbal oar
#

G'day, gentlemen.
What's a proper way to make multiplayer in Unity in 2020?
Since UNET is deprecated, should I use Mirror or Forge or whatever? Any success stories?

gleaming prawn
#

What kind of game(gameplay?

spring crane
#

Was UNet ever the proper way? πŸ˜›

verbal oar
#

What kind of game(gameplay?
@gleaming prawn Something RTS-like. 2-8 players controlling multiple units.

swift hill
#

?

gleaming prawn
#

Honestly, for an RTS, the only tool that would give you the right stuff out of the box for an RTS is photon Quantum

verbal oar
#

Was UNet ever the proper way? πŸ˜›
@spring crane At least it worked somehow. Though Mirror is advertised as "better UNET with fixed bugs"

gleaming prawn
#

Neither UNet, nor mirror, nor photon bolt, or photon PUN (put your state-transfer lib here) would be the right tool for an RTS

spring crane
#

The creator spent few years IIRC trying to fix UNet for use of his projects

verbal oar
#

Honestly, for an RTS, the only tool that would give you the right stuff out of the box for an RTS is photon Quantum
@gleaming prawn I can't afford it ($1000 per month, right?), my game is just a hobby project

gleaming prawn
#

Mirror is super nice, yes

#

Just not for an RTS

#

Well...

#

If you search here, I describe what you need

#

Is not "rocket science"

#

You can do your own poors-man version of this (very simple though)

#

I've recently discussed a lot about RTS here

#

I said out-of-the-box: quantum

jade glacier
#

Seems like a wiki needs to be made on this regular topic

swift hill
#

who to like gmod 12?

gleaming prawn
#

But you can certainly implement:

  • FixedPoint math (just search c# FP48.16 on stack overflow)
  • Your own determnistic simulation (with flow fields path finding, etc);
  • Your own lockstep (not fancy server-based predict/rollback like quantum) library;
#

You can use any basic transport layer like steam network, photon realtime free, etc

#

BUT, you need to start with the basics:

  • RTSs need determinism
#

So you can forget Unity Physics, Unity Navmeshes (and most asset store assets)

#

Seems like a wiki needs to be made on this regular topic
To replace that infamous blog post, lol

#

@jade glacier

jade glacier
#

LOL, yeah... that thing

gleaming prawn
#

And including reference to all existing production libraries from photon, mirror, and all vendors (free and paid)..:)

jade glacier
#

Start with that, and run lines through sections and correct them @gleaming prawn πŸ™‚

#

A lot of people say "hobbyist networking", but even that needs a lot of clarification. Like there is nothing "hobbyist" about trying to make an MMO that supports 100 players.

gleaming prawn
#

There are very very few exception to this rule @verbal oar : (RTSs are deterministic)

swift hill
verbal oar
#

I understand all of this, BUT:

  1. what about handling pathfinding and interactions on authoritative server?
  2. why I still need lockstep in 2020? It is just techique to reduce traffic and bandwitdth requirements. There is even an at least one RTS game (Planetary Annihilation) working perfectly without lockstep
gleaming prawn
#

One of them is planet annihilation, and it's not a simple model to implement..

verbal oar
#

A lot of people say "hobbyist networking", but even that needs a lot of clarification. Like there is nothing "hobbyist" about trying to make an MMO that supports 100 players.
@jade glacier I wouldn't ever need more than 6-8 players

gleaming prawn
#
  1. you don't need this... that's the whole point... Determinisim is authority... You just store the replays...
jade glacier
#

If you can live with latency for the players, server side non-deterministic is doable, but transferring AI states will decimate your bandwidth usages among other issues.

gleaming prawn
#

Using a server to mediate input exchange is enough to have fully auditable game results in an RTS

#

And RTS is a massive achievement @verbal oar

#

It's not simple

#

Lol, you got the point

#

Planetary Annihilation is a SUPER nice model, indeed...

#

But it's completely UNIQUE (and difficult to implement - there's no tool around doing that for you)... AAA studios today still use Lockstep... It's a perfect technique for RTS

#

Reason #1 to use determinism for an RTS (not mandatorily lockstep, although RTS under predict/rollback is overkill):

  • easiest way, BY FAR, to implement an RTS, and get A LOT of features out of the box (replays, authority, low bandwidth, etc)
#

That's it... This is a super repetitive topic IMHO..:)

#
  • Planetary Annihilation is awesome, but there's a reason other studios are not trying to do the same (it's not simple to implement)
#

And also: servers are EXPENSIVE...:)

verbal oar
#

Well... Ok, thanks. So there is no easy way to get rid of lockstep?
But my initial question was about which networking library for Unity should I use?

#

And also: servers are EXPENSIVE...:)
One of players can also be a host, I suppose

gleaming prawn
#

First, why do you want to "get rid" of it... This is the first question you should ask

#

πŸ™‚

#

One of players can also be a host, I suppose
Super complicated for an RTS

#

Lots and loads of bandwidth, requires reliable punch thrugh

verbal oar
#

First, why do you want to "get rid" of it... This is the first question you should ask
It has some downsides though

gleaming prawn
#

First: lockstep is NOT bad if done correctly... It's done all the time...

verbal oar
#

Super complicated for an RTS
I was sure that most of RTS uses this model