#archived-networking
1 messages · Page 111 of 1
👍
thank you very much worked.
Another question to that topic:
Can i let the game render shadows of a gameobject which is secative(false) ?
I have VR googles in the game and want the shadows to render but the player shoudln not see his self vr googles?
thats doesn't have to do with networking
i want to create unity mirror multiplayer game which is server based and it creates room automatically for max 50 players : room creation and player assigning to room is done in server : and game logic also done in server: I want to know where to start and how to do it
mirror has a rooms example and documentation
Can you share link to me
i am using Photon for Multiplayer.
the unity editor cant join Rooms that were created on any build of the game.
basically rooms created with builds of the game isnt visible for the unity editor
anyone know why?
please ping me if anyone responds
How can I ensure that all the requests are not only done before proceeding, but that it didn't send back a "rate-limited" JSON with nulls?
public static IEnumerator GetSpecificCharacterList(JikanCharacterListResult characterList, System.Action<List<JikanSpecificCharacter>> callback)
{
List<UnityWebRequestAsyncOperation> requests = new List<UnityWebRequestAsyncOperation>();
for (var i = 0; i < characterList.characters.Count; i++)
{
UnityWebRequest uwr = UnityWebRequest.Get(characterURL + characterList.characters[i].mal_id);
requests.Add(uwr.SendWebRequest());
}
yield return new WaitUntil(() => AllRequestsDone(requests));
HandleAllRequestsWhenFinished(requests, callback);
foreach (UnityWebRequestAsyncOperation request in requests)
{
request.webRequest.Dispose();
}
}
Here is the second function:
private static bool AllRequestsDone(List<UnityWebRequestAsyncOperation> requests)
{
return requests.TrueForAll(r => r.isDone);
}
Relatively simple, but about halfway through (say 50 requests) the API starts returning null values because it's rate-limited. I would like to restart the request if that's the case.
It probably wouldn't be a good idea to retry the entire 50 requests, so maybe I could store the ones that retrieved valid values and then try the ones that didn't work in order
hey i got mongoDB api working on my unity project by downloading like 20 addon dlls. will this work for clients though?? i know deadfrontier and a few mmos with like 100k players have been made.. but, i have no idea what thier database solutions were.
azure/fire base and the mongodb sdk are garbage
they are basically local databases..
but, the base mongodb is good. but, idk if it'll work outside of developer build.
Include something in the response headers that indicates whether or not you're rate limited
It does. The Game should render the shadow of an object Which is Invisible to the local player
May I ask then, how to do this code in a multiplayer way? Possibly server-auth cause the goal is a dedicated server. I understand that there're a lot of things wrong in this code but a general idea of what are the main problems and how to solve them would be really appreciated
https://pastie.io/kxpzbr.cs
well the question is, how do i render shadows of an object that is is setactive false. doesnt matter who it is really
So to start with, why all the if (true)?
for convenience to add something there later
Alright, that is obviously your choice, but I really recommend not doing that for readability, ill keep looking..
Yes
Can i use Playfab for A Project with Photon PUN ?
Cause i dont see PUN in the Playfab addons place, there appears to be only Photon Realtime and Photon Chat
Sorry what do you mean by response header? The uwr?
hello
I wanna know how to save some items and making it work with multiplayer
I'm using Mirror
and I want the Equipping, Unequipping and Dropping to be commands so they show up in the server
but I want the saving to be done locally
on the client
I have a pick up script that gives the item to an inventory holder, in the inventory holder a function gets called to updated an instance of an inventory and to update the ui
the UI updating needs to be on the client only I guess
how do i join a random room in unity HLAPI with custom button (if there is no rooms available then create and wait for other players ) ?
generally you want saving data to happen server side. also any data that is only on the client side wont be synchronized to other clients/server
if you are using a SyncList or SyncDictionary then you can add a callback function that acts as a hook just like syncvar
and then on the client whenever the callback is called you can change the ui based on the new value
But I have a lot of functions like equipping, unequipping, dropping
It's past 1 am rn so I can't work lmfao-
it works pretty well with this, check the documentation for synclist. it gives you the operation you did on the list/dictionary on the hook function, and then based if you added a new item to the inventory, removed one etc you can decide what to do
It's a bit more complicated
seems good for your use case imo
Can we talk tomorrow?
uh sure
Yeah
gn
sure np
It's a date! 
What the best method for this? (Mmorpg) balance of speed and security?
Maybe the struct?? I can make a limit of one.
Maybe 2 and 1? That way the client can read more easily through a gui when the skill will finish but have the actual change handled by a struct list that only the server side can see?
It's UNET, how do I fix this error?https://cdn.discordapp.com/attachments/497874004401586176/901727522906079272/unknown.png
@vital yoke I think your objects need to have the networking component
Network identity I think?
I think that was the components name
You are using an outdated networking solution though
already solved it
Hey, i was testing my invisibility feature and when i call my function(Code below) it ends the conection to the server but it doesnt give me any errors?
https://pastie.io/raw/hjmseg
(i use mirror btw)
oh and it only does it when another player is on the server
how can in sync objects?
Hey everyone!
I'm having a little trouble with Pun2 and I was hoping to get some help.
When I try to parent and switch ownership of a gameobject, it is very buggy for some reason. Here's an example: https://gyazo.com/85a2700d8a01014aea7158fdca8fad8d
Here's my script:
https://pastebin.com/U8Suj0jS
does someone tryed MLAPI?
is MLAPI supports kinda rooms?
when one player host many games
Using photon pun and running one game in unity editor and one through the exported build, the public float hp value for th player doesnt seem to be updating from client to client eg
client 1 hits client 2 and on client1 side it says client2's hp is 0 but on client 2 it says its still full
both of them have photon view & photon transform view classic
Photon view or transform have specific roles and won't sync that automagically. You need to use one of the communication methods of PUN to sync additional stuff, like RPCs. Check the docs for more.
i want to create room based server game on unity mirror multiplayer: how can i create new room in server when maxNumOfPlayer reach in a room and remove room when game on that room is complete
The PUN Basics Tutorial syncs characters, shots and health. That might be a good resource to help you solve your case.
https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/pun-basics-tutorial
hey dose anyone khow mirror networking i need help
Don't ask to ask, just ask
Hello everyone, I'm having some trouble with networking, can anyone help me out?
The issue is that I can't manage to send a request to my Node backend server, no matter what. When I request the server from Insomnia/Postman, it works fine. But when I do it from Unity, the server doesn't even register the request.
Additionally, it seems that the problem is specific to my internal network, since I'm able to send the same request to an external URL and it works fine.
I've already digged around the firewall rules, but the error remains even with the firewall off.
Any clues?
if anyone comes across this: the problem was with my WSL instance that wasn't forwarding properly, when running the server directly on windows everything runs great
Hi, can someone explain me shortly, how server authoritative movement works in general?
Does the client send the input to the server, the server handles the playerstate and send it back to the client?
How to handle high ping, etc.?
The client says which way it wants to go, the server calculates the movement and updates it for everyone, including the client who wanted to move
So basically, move forward, left, right, back, jump is commands the client can do
Does the client have to send the delta-time to the server, too?
Hm, why?
doesn't have the server to know how far the client moves in one frame, or do the client send the input in a fixed rate?
You cant trust a client with any kind of calculation
If you care about cheating that is
ok
So the client says move forward, and then the server calculates how far the player goes each frame
ok, but client-frame != server-frame. So how do you synchronize this?
Hm, I see what ur saying, I dont know if they need to be synced?
Atleast in my solution, the client only sends commands and looks what the server gives back
Good luck!
thx for your help 😉
another question: What if the server runs with (lets say) 30fps, and the client send more then one Input-packet between two frames. Does the server ignore the old one?
I dont think so, once a movement packet comes to the server, it calculates the new position and sends back the position to all players
But, you might not get that update until the next frame happens in the server
ok
so if the server has 2 movement-packets in the queue on the update loop, it calculates both movements?
Hey guys, I'm using MLAPI, I was wondering if there are ways to create RPCs with bool values
I need to add an item to a player inventory using a client RPC, and if the player has the inventory full the RPC function should fail, but I can't create an RPC that's not a void type
I'm not experienced with MLAPI, but I'm quite sure you can convert a bool into bytes and send it that way
Mirror has its own Discord - link is in asset store page
Mirror has its own Discord - link is in asset store page
Mirror has its own Discord - link is in asset store page - look for a channel there called "#insight"
Ok thanks
Hi, I'm new to unity but was wondering if photon would be well suited to a mobile turn based multiplayer game? I was looking at ue4 but it seems more geared towards instanced realtime shooter game sessions
You could check out their showcase. There's quite a few mobile realtime games. A turn based game would no doubt be a lot easier:
https://www.photonengine.com/en/realtime/showcase
Hey, when i export my game to webgl and connect (host is a normal pc build), it blackscreens (i see the player spawned in on the pc build). Ive made a simple ui with a connect button which loads just fine in webgl, it only happens when i press connect.
this is the error i get: host id out of bound id {254} max id should be greater than 0 and less than {1}
Any ideas what could cause the error?
Hey guys, I'm trying to do this but with JoinRandomRoom
Is it possible to do so?
Im trying to use PhotonNetwork.ReconnectAndRejoin();
Is it possible to have multiple games using Mirror running at a time?
how do i setup random spawn points mirror?
I have someone testing my game right now, and they're getting "socketexception: address already in use"
You can't use the same port for many different servers
you have a network spawn point component or something like that. put that on an empty gameobject and make its position to wherever you want and thats it. you can do it with as many spawn points as you want
Yes you just have to change the port. Ports can only be used one at a time like Welsh cow said
Hey guys how can I access a player prefab with a clientId in MLAPI? (Serverside)
@modern drift Thanks
can any one tell the example of local multiplayer for android ?? which works in above 2020 unity
Netcode for GameObjects and Mirror can both do that AFAIK
Which is Unity's latest multiplayer server ?
guys, I’m really stuck. I’m setting the player’s skin custom properties though Photon and only the local player’s skin changes - the others doesn’t?
Does anyone know why this is happening?
p.s: don’t gimme a “look on Google answer” please, that’s not gonna help since I already tried :)
here’s my code: https://toptal.com/developers/hastebin/ojuzadijiq.csharp
I'm using ParrelSync and Mirror, and I keep getting this error. I've removed and re-made the clone multiple times with no difference, and I've removed and re-made the Network Manager object, as well as restarted the editor
Network Manager object can't have a Network Identity on it.
Mirror has its own Discord - link is in asset store page.
That worked! Thanks!
Hey guys. Quick question, does adding multiplayer (in general not just unity) impact player fps? I'm only curious as I have zero experience in multiplayer
To be clear im not talking about increased players, more entities, etc.
hey, i am making a public void OnAfterDeserialize() { ClientPassContructionValues(); //Dispose //throw new NotImplementedException(); } for my scriptable object constructor on a multiplayer game. is there a different/better way to make a scriptable object from json values using private variables on the unity object? or, maybe even not as long as it's secure and not prone to exploits.
im loading / saving to my database just fine
but, its all in json atm. and i have scriptable objects for the clien. so they can read the update times etc
but, i wanna offload my server a bit
and make as much of this client side as physically ossible without making it insecure.
is there a video or a resource that goes into this?
the only 2 games that are mmos that used unity I know of are albion online and dead frontier but, in both of their interviews on gamemaking.biz they say they black boxed unity eventually and used their own dll plugins.. Is there anyway to use scriptables in a scope for an mmorpg? @viral widget cause you look helpful.
basically, cause of memory leaking people can theoretically change values.
and i do grab resource information for upgrading and saving.
and i dont wanna load from the database everytime i do this, its take 1 minute+ after a few thousand players to do this
so its much faster to keep a list, however, this is going to add a lottttt of ram up on a server if it needs to keep 1 mb od data for every player +1million
so, its not practicle.
Is there any way to create networking for free (without payed 3rd party software) or is Steamworks (Steam) capable of handling the whole multiplayer thing itself?
you could use player hosted servers
Sure, you can build the network layer yourself with TCP/UDP
There are great tutorials on youtube for this
@heady stump Is Unity Relay or Unity Lobby a good solution? Just read about it on the website that these 2 options are currently in Beta?
I dont know anything about those, sorry.
Okay. Thank you though 🙂
im using mlapi and adding in my own transport logic. this works pretty well actually too mlapi isnt definitely a decent base layer.
Has anyone here used PUN for MMO open-world based games?
how do I sync lists easily in Photon unity networking?
I'm getting these kind of errors with the new Netcode release:
OverflowException: Reading past the end of the buffer
Unity.Netcode.Components.NetworkAnimator.ReadParameters (Unity.Netcode.FastBufferReader reader, System.Boolean autoSend) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Components/NetworkAnimator.cs:396)
Unity.Netcode.Components.NetworkAnimator.SendAnimStateClientRpc (Unity.Netcode.Components.NetworkAnimator+AnimationMessage animSnapshot, Unity.Netcode.ClientRpcParams clientRpcParams) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Components/NetworkAnimator.cs:427)
Unity.Netcode.Components.NetworkAnimator.SendAnimStateClientRpc__nhandler (Unity.Netcode.NetworkBehaviour target, Unity.Netcode.FastBufferReader reader, Unity.Netcode.__RpcParams rpcParams) (at <c9cf9d45b44c4ede894402c60534568f>:0)
Unity.Netcode.RpcMessage.Handle (Unity.Netcode.FastBufferReader reader, Unity.Netcode.NetworkContext& context, Unity.Netcode.NetworkManager networkManager, System.UInt64 senderId, System.Boolean canDefer) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Messaging/Messages/RpcMessage.cs:93)
Unity.Netcode.NetworkBehaviour.__sendClientRpc (Unity.Netcode.FastBufferWriter writer, System.UInt32 rpcMethodId, Unity.Netcode.ClientRpcParams rpcParams, Unity.Netcode.RpcDelivery delivery) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Runtime/Core/NetworkBehaviour.cs:193)
Unity.Netcode.Components.NetworkAnimator.SendAnimStateClientRpc (Unity.Netcode.Components.NetworkAnimator+AnimationMessage animSnapshot, Unity.Netcode.ClientRpcParams clientRpcParams) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Components/NetworkAnimator.cs:415)
Unity.Netcode.Components.NetworkAnimator.FixedUpdate () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.2/Components/NetworkAnimator.cs:228)
anyone knows what's going on here?
Is MLAPI good to start with?
I want to make a soccer game where players and balls are rigidbodies
The problem is that from client view pushing ball is laggy and awkward. I know that to synchronize movement we need to use NetworkTransform but when I use rigidbody.AddForce it seems it breaks it at all.
If you use Netcode for GameObjects' latest release (That's the new name for MLAPI) it has NetworkRigidbody
hello
so I have this item object I can equip
I grant it authority
it returns true when I check it in the update function
but when I call any networking function, it just gives me a null reference error
it doesn't start the function itself
it's not that the function has something missing
this is how I'm granting it authority:
NetworkServer.Spawn(itemToEquipObject, connectionToClient);```
this is all done in a Command function
debugging it returns connection(0) which I'm fairly certain is good-
Yesterday it let me load image urls to Unity, but today I get this error. Any solution?
It means the server you try to access is unavailable
If it's not your server you can only wait till it gets back
I'm not sure if I remember this right but when using UNet I remember that you could set local authority on a player and that made it possibly for a client to move their own Transform thus synchronising it on the server (Client authority). I can not find that alternative in the new NetCode?
https://docs.unity3d.com/Manual/UNetAuthority.html (Local Player Authority checkbox)
This is what my LocalPlayer NetworkObject looks like on the client.
Try fusion, it is making some big changes and lag and whatnot is fixed, and they use prediction to move.
Using a self built tcp/udp network layer, do you need to verify which client is whom by a token or something similar after the handshake is complete?
I do that with each UDP packet I receive, if there's no identifier or a wrong one then the connection will be closed
So a clientid and a token to verify for each packet?
I don't necessarily enclose a client ID with each packet, but a token of some sort definitely
Alright thank you!
That way I can at least be more or less sure they aren't spoofing packets and pretending to be someone else
Yea, you can always bruteforce I suppose
The tokens don't even need to be that unique either, as long as nobody knows tokens of other users it's good enough imo
I use a 4 byte token, but I could've used a 2 byte one as well and it would still probably be sufficient for what I need it for
2 bytes is still about 65k possible tokens so nobody is going to brute force guess that without getting noticed
In my case I just disconnect them instantly if the token is missing or incorrect
For as far I know (I could be wrong) it's not needed because TCP actually has handshaking built in
UDP is connectionless, which means just send a packet and forget, there in essence is no real connection and no handshaking
Do you use TCP for reliable transmission?
I thought so, maybe consider looking into something like ENet which is what I use
It can send reliable over UDP
ENet is some Unity thing?
It definitely beats having to use 2 protocols which has its own problems
It works with Unity let me put it like that
I take it that you did your own networking from scratch?
Yea
In that case you don't have much to lose with ENet I think
Because it does all important stuff already for you and it is very simple to get going, you just build on top of the base that it gives you
Alright, ill check that out as well then, but I still need to add tokens in the packets, right?
I recommend that over doing it from scratch because it's a solid library which allows you to do everything on UDP
Yes you still need that
Ah its only UDP, gotcha
https://github.com/nxrighthere/ENet-CSharp this is the one I use
You can look at the example there on how it works, it doesn't get much simpler than that. I recommend this to anyone who doesn't mind working from a low level point of view but still want to get going quickly
Cool, I mean, I have everything already working, I just started thinking about security
Yeah that's a thing you definitely need to address
Also doing checksums for data integrity
Quite sure ENet can do that as well but I've done my own and it works really well so far
I'll be honest, I dont even know what that means 😄
Ok I'll try to explain in a few words
Whenever you send data over the internet, it may lose some bits or some bits get flipped which makes your data corrupt. A checksum can help to check for whenever this has happened. From a high level point of view you calculate a sum of the data, which gives you a number. You send this number with the packet, and when you receive the data, you compute the checksum again and check if it matches the checksum that came with the packet. If these 2 numbers match, the data can be considered unchanged
If the 2 numbers don't match, you drop the data cause it has been changed due to one of many different causes
Oh, so the sender sends a checksum in the packet so that the reciever can doublecheck the data?
And that is both ways, client -> server and server -> client?
Yes both ways
Ah cool, what if that checksum is corrupt tho? U just ignore the packet i suppose
I do this with any packet, and for sake of simplicity the first 2 bytes of my data is always the checksum
Yeah if after computing the outcome doesn't match the supplied checksum you just ignore the packet
Great, got it
There are established ways of doing this though, so if you're going to look at this, try find some working implementation on github for example and play with it for a bit to make sure it does what you expect it to do
Would you mind sharing how you calculate your checksums or is that too much to ask after all this explaining? 😉
I haven't written everything myself I take shortcuts where possible
I can send you the code I use in a DM
Appriciate it!
Can soneone help me with this?
The object has authority
But I can't call the functions
K guys, i have no idea about networking.
But still have a question.
Is it possible to make some sort of connections trough IP address like in Minecraft, Terraria, Cube World without buying server for that
If its possible i would like to read something about it
Is the ordering of my base.Whatever()s compared with the other code in the function correct?
For functions that create something I should run the original first then run my own code, and for functions that destroy something I should run my own code first, correct?
I'm using Mirror, but I don't know if that really matters for this question
I’d check if the base method isn’t just an empty virtual one
If it isn’t I’d put my code after base on anything but disable/disconnect/destroy/etc.
Ok, thank you
How do I know which server I'm on? I'm using this code
The server URL is inside that MediaUrl, not sure where you got this code from but it leads me to believe you are not very familiar with the codebase you're working with
Yes, everything worked yesterday. But today it does not work and this error comes out
Like I said before the server is unavailable. This could be because of many reasons. If you don't own the server then you're out of luck
Some servers also disallow GET requests from applications that aren't web browsers. I don't think this is the cause of your problem because you'd probably get a different error unless they just dish out a 503 in general if they don't want to respond to the request. Either way, if you don't own the server that you're doing a request from then you have zero control when something goes wrong and it just breaks the functionality of your application/game
So time to rethink whatever you're trying to do
Hello everyone! I'm trying to authorize Firebase using Facebook.
For several days now I have not been able to solve this problem. One and the same error constantly takes off. I've already tried a bunch of methods from google, but nothing helps, so I think whatever you suggest is something I've already tried.
Simple Facebook Authorization is working. Simple Firebase Authorization via Email/Password is working. But together this guys dont wanna work
The last thing I hope for is that the problem is in my code. Because auth.CurrentUser == null. It seems to me that there is something with asynchronous here.
There is my script https://pastebin.com/iTh7mPRX
Help Please.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
@orchid inlet Don't cross-post, pick single relevant channel next time.
I just didn't know where i should post it
Hi! I want to create a game with in-game mail in it. Which I want to send gifts for clients from server to game I'd (id created by Google, Facebook,twit,etc..) to a specific player in mirror. How do I make it Can some one help me?
Does Netcode for GameObjects support dedicated server?
Does anyone know an imgur, but for audio files?
I just wanna download .mp3 files with unitywebrequest
Does anyone know the difference between mirror and steamworks
Mirror is a library that helps you with implementing multiplayer networking, I.e. real-time messaging and sync of game state. Steam works are tools that help you publish/deploy/sell/maintain your game; Part of it is a lobby feature that you can hook into with your game.
Thanks
If you are looking to use both you can use FizzySteamWorks
it implements both mirror and steamworks
Ok I will look into that
public override void OnClientConnect(NetworkConnection conn)
{
base.OnClientConnect(conn);
NetworkClient.localPlayer.name = "Local Player";
Debug.Log("Connected");
}
I'm using Mirror, and have this in a custom NetworkManager. It seems to work fine on the host player, but just produces
System.NullReferenceException: Object reference not set to an instance of an object
at ArenaManager.OnClientConnect (Mirror.NetworkConnection conn) [0x00007] in D:\Github\Artifacts-of-Punishment\Artifacts of Punishment_clone_0\Assets\Scripts\Networking\ArenaManager.cs:17
on the client. Line 17 is the one that sets the name. I believe localPlayer is null. Any ideas to fix that?
are you sure that you are allowed to write to localPlayer?
I get the same error with Debug.Log(NetworkClient.localPlayer.name);
And I just tested Debug.Log(NetworkClient.localPlayer);. I got Null
Alright, wish I knew more about Mirror to be able to help, afraid I dont, good luck :p
Thanks for offering what you could
player object doesnt exist when OnClientConnect fires... use onStartLocalPlayer in network behaviour on player object
Yep, that fixed it! Thanks
Hey guys, can anyone explain what the point of Unity.Networking.Transport is? What does it provide over c#'s networking api?
I've been looking for an explanation online but there doesn't seem to be much beyond Unity's own documentation
I wrote a networking solution for my game a long time ago but it's a bit messy. I want to write a more robust version that I could easily extend with support for peer-2-peer networking, server authoritative networking, steamworks, or whatever else I feel like adopting down the line.
You might want to look into lidgren, it's kind of a midway between straight up socket programming and Mirror. Gives a good amount of control over what data you're sending and doesn't abstract away too much.
It is a bit hard to find resources though, admittedly
Thanks! I'll look it up right now
Yeah most people don't seem keen on building all of this themselves and would rather use mirror or some other solution instead
I don't need all of the high level stuff that those systems provide though. Just reliable message passing.
It doesn't even have to be that fast
Sockets are a major pain that's why lol, tho I'm not a fan of mirror either
It’s the low level transport layer for the new net code. Handles message encoding and reliability on top of UDP. Similar to enet, lidgren, kcp, ruffles, …
Lidgren basically takes care of the handshake + sending messages on different channels (Reliable Ordered, Unreliable Ordered, Unreliable)
And then you can define the bytes in the actual message if you'd like
Oh that's what a transport layer is...
transport gets you talking but nothing else
You learn something new every day, finally I know what to google!
No validation, no auth., no rpc, no network variables, no portals, no manager….
if you use netcode for game objects (ex MLAPI) you get some abstraction (rpc, basic network variables), with mirror you get high level abstraction and ready to use components
Okay okay so it's a net benefit over c#'s networking layer I guess
that’s got nothing to do with c# other than that it is written in c#
Although I was already using tcp before so maybe it wouldn't provide that much in my case
tcp is just a protocol
I mean vs just using c# listeners and sockets directly
Well it has built in reliability no?
Yes, and a lot of waste
Yeah but it's turn-based strategy so speed really isn't a concern
Still though I'll take improvements if they're free
TCP is protocol level reliability, enet & co. Are built on udp and have custom/configurable reliability
probably true… could even use a rest api (please don’t)
Lol for a second you had me wondering what that would provide 😂
Not sure where else to put this, this seemed to be the best channel for this:
So recently, my hard drive died, and I've had trouble pulling up the collab project I'm a part of on the hub ever since, and Unity is not giving me an option to refresh even though my other team members can pull it up just fine. How do I fix this? Thanks!
what platform are you getting it from?
like is it on the unity collab thingy?
Hello.
I have a Unity project that uses MySQL and PHP.
I need to print Date from server in the Canvas.
so I've made this:
This is my code: https://www.toptal.com/developers/hastebin/oxufahinig.csharp
And this is what it prints in-game.
it should print "Hello today is 2021-10-30 13:03:15"
If you can print it in the console, why don't you use the same method to print it to the text box?
what do you mean? didn't I already made it?
line 36?
On line 33 you can print exactly what you want just fine
Then on line 36, you do some weird Get again, which you then ToString?
I don't quite understand why you changed how you try and get the text you want, when you literally Debug it exactly as you want it?
thank you so much, yes. I did not know "downloadhandler" was the output lol
now it works, thank you
I’m interested in getting into game networking, but I don’t know where to start. Should I just create my own TCP sever and client, or do I use some framework? Also any recommendations for blog posts on tutorials for game networking (specifically ecs related since I’m trying to get into that).
I really recommend this tutorial by Tom Wieland. It's a very basic TCP/UDP setup for a dedicated server with clients. It's basic because there's a lot missing for it to be used in a production environment, but you can play around with it and learn a lot about low level networking, I certainly did 🙂
In this first part of my C# networking tutorial series, we set up a TCP connection between a dedicated server and a Unity client.
If you get stuck or have questions, ask them on my Discord server: https://tomweiland.net/discord
Kevin Kaymak's channel: https://www.youtube.com/channel/UCThwyD-sY4PwFm7EM89shhQ
List of commonly used ports: https://...
i'm trying to do networking with mirror, but the NetworkTransform doesn't seem to be updating
the other player appears when they join the server
but they're frozen in place
that sphere is the spawn point
and the other player doesn't fall because I have
if (!isLocalPlayer)
{
return;
}```
in update
so my gravity code only runs clientside
but that clearly means that the transforms aren't updating across the server
and moving both clients doesn't change the position of the other one
i've got these settings on the player prefab
Whats the best package or method to run two instances of the editor at the same time for testing multiplayer functionality
I've seen different competing solutions, from project cloners to editors scripts
Assuming the networking solution doesn't natively support that, using ParrelSync to clone the project for 2 editor instances is the way to go.
ParrelSync was one of the options I saw, you recomend it?
I switched from MLAPI to Netcode for GameObjects and I have a problem with moving player by client. When maps spawns client can't move his GameObject but he is able to see what host does and host can move the client by pushing him. I'm using rigidbody to move the players but the problem is that only host is able to move, client is not.
I use NetworkRigidbody to sync properly movement on both players. By debugging i know that input from client is known but it doesn't seem to react by move.
hello
can someone help me with authority?
I have these items I wanna spawn
after instantiating, I use the NetworkServer.Spawn method and give them authority to the client
it works, if I debug it it returns connection(0) which I'm 99% is correct
but I cannot send any network function
like commands, rpcs etc.
it returns a null reference error
and doesn't even start the function
now that I think about it, it might have something to do with the assemblies
but again
I have no idea
nvm
it's not that
it's giving me a lot of errors about not having references in the networkbehaviour script
the entire script is just
returning errors for some reason-
I can't use isLocalPlayer, I have to use GetComponent<NetworkIdentity>().isLocalPlayer
why don't they work-
wtf-
Wall of text incoming:
I've been implementing my (very first) from scratch UDP multiplayer and it's been working pretty "OK". I've done the following things, maybe somebody has some tips for what I missed?
- The game is physics based
- One client "starts the game" as a host/server. The server listens for incoming UDP traffic. (peer to peer model)
- Client B, C, D connect to the server. The server adds the new player to the game and sends a packet to each already connected client to add the player.
- The clients receive a "keyframe" for each player containing all the needed positional data, body data, hp, etc. every 0.5 secs (but in theory this is redundant because the real time packets like the input and damage packets should keep the players in sync)
- Each client runs the physics simulation on their own. But any damage received is set to 0/zero because the server is authoritative on that.
- When a player receives damage, a packet is broadcasted (send to each connection one by one by the server) informing the client to update the hp to the same as the server.
- Clients send their inputs every time/frame that it is not the same as the last one. When the server receives the new input it applies it to the game and broadcast the new input to the other clients. If no (new) input packet was received the other clients and server assume it should repeat the same input as the last packet
- A "just in case" input packet is send every 0.5s to account for any missed/dropped input packets
- The server is listening to the socket async, adds the received packets to a queue and the server then processes all the received packets in the FixedUpdate() (main thread).
- All the packets send by the server to the clients are buffered for one FixedUpdate() and grouped until they reach a maximum size (currently 1200 bytes to fit most MTU). While using wireshark I can see that they are indeed grouped together.
(continued...)
- All client packets are being synchronous (blocking) send as far as I understand UDP sending is not really blocking anyway on this scale.
- I've optimized packet sizes by only using the bare minimum of information, and using the least bytes possible for each datatype
- For example compressing a float -1 to +1 into a "low precision" single byte
- With one client connected the in+out/server+client packets are ~260 bytes/s with an average length of 73 bytes and 5 packets per second. I really have zero frame of reference wether this is good or bad, any insights are appreciated.
- One issue that I suspect is that there is no lag prediction other than the client running physics himself. In the scenario that he receives a keyframe with positional data that is "old" (lets say 500ms) all the players will get teleported 500ms behind the current server state. The next keyframe is then received in 10ms and yanks everybody back to the server state, this can ofcourse repeat multiple times in a row and makes for a stuttery experience. I have been reading about the server having a (500ms or so) buffer essencially being behind but I can not really see how that would work with my current client as a server model. I could maybe try to sync the frame number when connecting and adding the frame number to each keyframe. Then if a player receives a very "old" keyframe they could just ignore it or extrapolate from there? I'm not sure how to do that, should I run FixedUpdate for the N-number of frames that the keyframe/packet is old?
Possible TODOs, which will make a big impact?:
- Use compression on packet data?
- NAT punching (currently the game needs to have the ports forwarded on the router)
- ACK for critical packets (there are very little critical packets that are not repeated at least every 0.5s)
- Ensuring ordering packets (avoiding out of order inputs, repeating the last, incorrect one, although almost always corrected within 0.5s)
Do you guys know any free or cheap website I can test my headless Unity server on?
Hello everyone,
I'm currently trying to wrap my head around networking. I would like to to create an RTS with deterministic lock-step.
So I imagine that primarily all I really need is client-hosted servers (I don't want to deal with NAT if possible).
The clients (including the host) would send their commands such as 'order this unit to a certain location' to the server.
The server would then gather all these messages up and send them back to the clients on the next game logic tick.
Of course this could be complicated further to improve the player experience but this is the base principle everything would be built upon.
Any suggestions what library I could build this logic ontop of? Is it possible to implement such a thing with Mirror?
Would Mirror Network Messages be a good fit for this?
I have a question about how I should code in multiplayer
I am using mirror and here is how my inventory script works:
I have these commands
Interact, Add/Remove Items, Equip/Drop Items
in add and remove it's pretty simple
the server adds the items to the clients which is saved locally (it's fine for this project)
but for equipping and dropping it's like this
public void CmdDropItem(ItemSlot itemSlotToDrop)
{
if (itemSlotToDrop.itemId == equippedItem.itemId)
{
equippedItem.amount--;
if (equippedItem.amount < 1)
{
NetworkServer.Destroy(equippedItemObject);
equippedItem = null;
}
}
Rigidbody groundItem =
Instantiate(GameManager.instance.groundItemPrefab, itemHoldPoint.position, itemHoldPoint.rotation)
.GetComponent<Rigidbody>();
NetworkServer.Spawn(groundItem.gameObject);
ItemSlot itemSlot = new ItemSlot(itemSlotToDrop.itemId, 1, itemSlotToDrop.regionName);
groundItem.GetComponent<ItemHolder>().SetItemSlot(itemSlot);
groundItem.AddForce(itemHoldPoint.forward * 50);
RemoveItem(itemSlot);
}```
and this is for dropping
should I make the server update a certain item on the player
like
an int let's say, that holds the id of the item
and have clients subscribe to an event and update the graphics on their clients?
I just want to know how I should code stuff like this
I'm no expert but it would seem to me you want the server check to make sure duping isnt happening, So client would send a drop request to server indicating the slot from which they want to drop, the server sees whats in that slot and if any is then it removes it and spawns the ground object pushing both changes to the client for graphic updates.
Mirror has its own discord, just Google mirror discord it should pop up
Aight!
Thanks!
I started playing with unity transport recently and have a question: why does e.g. BeginSend return an int when it's actually returning a variant of Error.StatusCode? Imo the latter is way more descriptive.
Also, has anyone got their samples to work? The ping sample doesn't work for me at all, it spams the console with "error on receive ..." before even starting the connection
I'm really scratching my head why does not work? (not before or after socket.Bind()).
socket.SetIPProtectionLevel(IPProtectionLevel.Unrestricted);.
it gives me SocketException: An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call..
Code is working fine on inside NAT, but I can not get it punch a hole with a match matching server. (Wireshark says Destination unreachable, Port unreachable)
Has anybody done a custom UDP implementation with NAT hole punching? I can connect just fine with port forwarding but nowadays I feel like users don't know how to do that anymore.
Is anyone else having issues connecting to Photon right now? My Photon Networking suddenly stopped connecting...
You need to use a stun server or implement your own on your matchmaking server
Nevermind its working...
can someone give me some ideas on how to debug my multiplayer game?
left/right rotation is updating between clients over the sever, but up/down rotation and movement isn't
i'm at a loss for what to try
depends on the networking you use man
I'm using Mirror
with an aws server
Mirror uses a component called a NetworkTransform to send transform data over the server
the one on my player looks like this
Scripts that locally control those things are generally sus, so the most likely reason is that something is overriding those things when they shouldn't.
I wondered about that but I don't think that can be the case
because all of my code is called from update
and in Update, FixedUpdate, and LateUpdate, I have at the beginning of the function:
if (!isLocalPlayer){
return;
}```
so my understanding of how this works is that the player changes his position locally
then the NetworkTransform component sends that data across the server
By default the Updates will keep running
right but isLocalPlayer is only true when the player gameObject is spawned by the client
so other players' scripts will have isLocalPlayer set to false
Yea that should solve it
but I already have that code that returns from update if not the local player
Could have a physic object drop from the sky or something to see if it's Mirror or something to do with your player scripts
It's pretty unlikely for Mirror to be broken in such a specific way 😄
thanks for the suggestion. I added a cube that falls from the ceiling, and with both a network transform and a network identity it didn't show up on the other client
the players spawn in and update left/right rotation
but nothing else seems to work
@south palm mirror has its own discord where we can pick apart your issue, just Google mirror discord
Plenty of helpers there that will know
Yeah it's the one with the frog icon, don't ask me why they set it to that lol
yeah! I've got a match maker server.
- Alice hosts a game, connects to master server (MS), MS remembers the connecting public IP/port for Alice.
- Bob presses "join a random game", connects to MS, MS remembers Bobs public IP/Port.
3a. MS then sends a packet to Alice with the public IP/port for Bob, Alice starts sending her game session data to the public IP/Port of Bob (IMCP port unreachable) to open a hole on her side.
3b. At the same time the MS sends Bob the public IP/port for Alice to Bob. Bob now starts sending "request game info" to Alice on the received IP/Port combo for Alice.
Now the problem is that Alice's packets never arrive at Bob and Bob's packets never arrive at Alice. However both Alice and Bob are able to talk to and receive from the master server. Every example online that I saw seems to use that SetIPProtectionLevel(IPProtectionLevel.Unrestricted) but it's not working for me in Unity.
I'd love any advice on how to debug this. I've tried this yesterday as well with a friend on a different LAN, and it also did not work, I've disabled the Windows Firewall. I know that some third party plugins are available but it my code is very optimized for my game and I would prefer not to rely on a third party plugin. Working well on LAN or WAN + port forwarding, but having the NAT punching would make such a difference. All I need to know is this black voodoo they perform to punch the NAT!
last time i wrote a nat puncher inside unity, i just used udpclient, didnt need any extra ip protection stuff
Okay, that is good to know! I'll have to look for other problems.
you are going the right direction, but just remember that there are some NAT Type combinations which make direct connections actually impossible, so it's never possible to cover all cases...
Statistics from steam (reference missing) and ourselves show around 85-90% success rate
any idea why my network transform is transmitting left/right rotation perfectly across the server, but up/down rotation and movement aren't being updated at all?
movement:
characterController.Move(moveDirection * Time.deltaTime);```
left/right rotation:
```cs
transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);```
up/down rotation:
```cs
spine.eulerAngles = new Vector3(rotationX, spine.eulerAngles.y, 0.0f);```
You need to explain a bit more about your solution, for example what kind of networking you use; for example Mirror/Photon.. and then show more of your code, this dosnt say much tbh 🙂
Alright my isolated test case seems to work (so it is possible at least for my router pfew), so here is the code for UDP NAT traversal if anybody runs into the same issue at some point. Note that a rendezvous/master server needs to be running somewhere (i'll have to leave it as an exercise for the reader). That just needs to capture and resend the public ip:port to both parties wanting to connect to each other. Related terms are STUN, TURN and ICE. Missing features: no support for local LAN (192.168..)! Does not work on a single NAT (two computers connecting to the same network) due to hairpinning which confuses the router. Disclaimer: not all types of routers/LAN are able to do NAT punchthrough your milage might vary.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I'm using Mirror. The compete script that controls my player's movement and input is posted here. https://www.toptal.com/developers/hastebin/unijoxuhij.csharp
the network components on the player look like this:
Anyone know what's wrong with this code? (I'm making a multiplayer card game, there are two sides, when one client draws cards, on their end it should appear on the player area while on the other client's end it should appear on the player area, however this doesn't happen at all.)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class PlayerManager : NetworkBehaviour
{
// PUBLIC VARIABLES
public GameObject Card1;
public GameObject Card2;
public GameObject PlayerArea;
public GameObject EnemyArea;
public GameObject DropZone;
// LISTS
List<GameObject> cards = new List<GameObject>();
// OnStartClient is called before Start, and is only run by the Connecting Client
public override void OnStartClient()
{
base.OnStartClient();
PlayerArea = GameObject.Find("PlayerArea");
EnemyArea = GameObject.Find("EnemyArea");
DropZone = GameObject.Find("DropZone");
}
[Server] // Prevents the client from executing the functions embedded beneath
// OnStartServer is called before Start, and is only run by the Hosting Server
public override void OnStartServer()
{
cards.Add(Card1);
cards.Add(Card2);
}
[Command] // Marks the below functions as server commands
public void CmdDealCards()
{
GameObject card = Instantiate(cards[Random.Range(0, cards.Count)], new Vector3(0, 0, 0), Quaternion.identity);
card.tag = "PlrCard";
NetworkServer.Spawn(card, connectionToClient);
RpcShowCards(card, "Dealt");
}
[ClientRpc]
void RpcShowCards(GameObject card, string type)
{
if (type == "Dealt")
{
if (hasAuthority)
{
card.transform.SetParent(PlayerArea.transform, false);
}
else
{```
card.transform.SetParent(EnemyArea.transform, false);
}
}
}
}
nvm i fixed it lol
Never used Photon so I can't help ya, soz ;-;
Hello everyone! I'm having trouble understanding the Unity Multiplayer Networking (Netcode). I don't trully know how to implement my rigidbody2d based movement into multiplayer with the ServerRpc and ClientRpc, i'm a bit puzzled !
hey guys how to fix error CS0111
a quick google found me this:
The namespace '<global namespace>' already contains a definition for 'PauseMenu'
This error means that you've written a class with a certain name, but there is already a class with that name in your project. You can't have two classes with the same name unless they are in different name spaces.
Some possible causes of this error are:
- C#, Unity, or an asset that you installed already had a class named PauseMenu
- You wrote a script named PauseMenu and accidentally made a copy of it.
- You updated an installed asset with scripts and for some accidental reason, it created a duplicate of the script instead updating the existing script.
So how to fix it
what is the text of the error?
It says Type MenuManager already defines a member Called 'OpenMenu' with the the same paramter types
I assume you haven't written any code where you call something OpenMenu, have you?
here I will show you the script
What do you mean
do you know what a Class is in programming?
yep
have you written any classes in your code
yep MenuManger
ok, so you declared a class called MenuManager?
so the error you're getting seems to be because your MenuManager class has two members called the same thing
namely, OpenMenu
just rename it to something else
Ok
try Open_Menu or something
anyone have a good tutorial for the basics of networking with MLAPI?
well, for the basics of networking in general. I've looked through the official docs but the information is a bit scattered
Hey guys, im using PUN2 from photon for a unity project, but when I call a PunRPC method i get this error:
Caught exception in OnEvent() for event code 200: System.Reflection.TargetInvocationException
.
I'm pretty lost as to what this could be from
ThrustSystem is a particle system which is a child of my player
JB, not an expert on this matter but my suspicion is that it's getting 'double-called' when there's several keys being pressed. Maybe try isolating the if-else for the mouse1.
ok so I've got a gun script that extends MonoBehavior and it fires a bullet like this:
private void shoot_primary_ammunition(){
GameObject fired_bullet = Instantiate(ammo);
fired_bullet.transform.position = bullet_spawn_point.position;
fired_bullet.SetActive(true);
// raycast
Vector3 target_point = Camera.main.ScreenToWorldPoint(reticle.transform.position);
Ray ray = Camera.main.ScreenPointToRay(reticle.transform.position);
// launch the bullet towards the raycast
fired_bullet.GetComponent<Rigidbody>().AddForce(ray.direction * fired_bullet.GetComponent<Projectile>().speed, ForceMode.Impulse);
player.spawn_object_on_network(fired_bullet);
}```
and that last line is calling this function on my player script that extends NetworkBehavior:
```cs
[Command]
public void spawn_object_on_network(GameObject obj){
NetworkServer.Spawn(obj);
}```
so why are the bullets only spawning clientside and not serverside?
Hey guys, just popping by here to ask if it's worth starting a networked game with Unity's networking system so far.
I've made small scale games with previous iterations like uNET, then moved over to Mirror, and made some games there, but ultimately all of them had massive limitations and weaknesses.
Is Unity's new networking system MLAPI?... or is it called Netcode for GameObjects? Some places I see the first name, some places I see the other name.
to my understanding it is built from MLAPI yes
It's both. The former was renamed to the latter. Much like LWRP/URP
I'm using Netcode and I would like to sync a trigger of a child GameObject
but I can't get it to work
the trigger never gets synchronized
We have renamed MLAPI to Netcode for GameObjects.
Is it at a point with it's worth starting to build a networked game with Unity's Netcode? Or still too early?
how do I get my local LAN IP address using MLAPI (or Netcode)
{
return Dns.GetHostEntry(Dns.GetHostName())
.AddressList.First(
f => f.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
.ToString();
} ```
hello i have this error
Failed to 'network-remove' GameObject. Client is neither owner nor MasterClient taking over for owner who left: View 0 on AK-47 Bullet(Clone) (scene)
UnityEngine.Debug:LogError (object)
Photon.Pun.PhotonNetwork:RemoveInstantiatedGO (UnityEngine.GameObject,bool) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:802)
Photon.Pun.PhotonNetwork:Destroy (UnityEngine.GameObject) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2785)
Com.Artur.FpsGame.BulletScript:OnCollisionEnter (UnityEngine.Collision) (at Assets/Scripts/BulletScript.cs:32)
idk how to solve it
Hi there,
can somebody please tell me, why I can not find any Method to disconnect the NetworkManager when using netcode 1.0.0?
According to this documentation: https://docs-multiplayer.unity3d.com/docs/components/networkmanager
there should be a call like: "NetworkManager.Singleton.StopClient();"
But I can not find anything like this in my code. The methods for starting the server/client work fine though.
The NetworkManager is a script component handling all your Networking related settings, your Networked Prefabs and your registered scene names. A Transport component is needed on the same GameObject. It is responsible for handling IP adresses and additional settings.
I think they consolidated it into one method called Shutdown
Is mlapi still in beta?
and would I have to use different transport to get rid of port forwarding?
It is called ‚Netcode for GameObjects’ now
I knew that but I forgot the name
So is it still in beta?
Well, it is 1.0.0 but ‚preview‘ … whatever that means
usually 1.0.0 means ‚stable‘ as far as the api is concerned…
In terms of documentation and examples/resources it has long way to go (compared to mirror). So kinda beta in that regard.
I could just read unet/mirror's documentation since all of them work the same
Yeah there's a lot of similarities, so you might find that systems that work in Mirror are easy to translate over to NGO
Devil is in the detail
and netcode hasn’t nearly as many ready made components to use
it's released when they strip the pre suffix from that package.. right now latest version is 1.0.0-pre.3
if they release 1.0, it will be 1.0.0 without anything extra, but in past they've often also bumped the package a bit before first stable
Isn’t that what I said?
ah, I thought there was some confusion, mb
i wouldn’t rely on convention and anecdotal evidence when stability of unity api is concerned
Based on that, pre is effectively stable
lol
but yeah, exp packages can be stable too, main difference is that API can change a whole lot more during experimental phase
but even with released packages, that's nowhere given it's not going to have totally different API on future version
ther is no stable ‚after the fact‘.., stable is a promise of ‚no breaking changes‘
That’s what versions are… they won’t break something and release it under the same version
ok I'm not trying to bring some debate here, carry on
i have a project I will be starting and I am unsure if unity owuld be the best thing for it. It is a 2D project with a lot of peeps inside.
(Using Mirror. This script is attached to the player object, which has client authority)
This section of code produces this error
Disconnecting connId=0 to prevent exploits from an Exception in MessageHandler: ArgumentException The Object you want to instantiate is null.
at UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) [0x00049] in <a0ef933b1aa54b668801ea864e4204fe>:0
at UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) [0x00001] in <a0ef933b1aa54b668801ea864e4204fe>:0
at PlayerController.UserCode_CmdSpawnObject (UnityEngine.GameObject prefab, UnityEngine.Vector3 position, UnityEngine.Vector3 rotation) [0x00007] in D:\Github\Artifacts-of-Punishment\Artifacts of Punishment\Assets\Scripts\Player\PlayerController.cs:54
But this section of code works completely fine, spawning an enemy on the server. I believe the reference is being lost when it moves to the command. Does anyone know why this would be?
@swift epoch you can't send prefab over the network
or it must be NetworkIdentity
correct, only way you can send gameobject is if its already network spawned with an identity
I modified it so it just used NetworkServer.Spawn in [Client]. Does that even work?
I broke my networking so I can't test it over that, but it works great locally
No you can't use network server spawn in client context
It won't sync
only server can spawn
Oh, so what would you guys recommend then?
you can either redesign to make it so that the server doesn't need to be told what to spawn, or you can get the index of the prefab in the spawnable prefab list and send that instead then look it up on server
Oh, I might just do that second option. That's how I was doing it before my redesign
Thanks. Looks like this is the method I was looking for.
Is there any sample with Netcode for GameObjects and authoritative physics?
(Using Mirror) How am I supposed to use NetworkBehaviours on children? I tried researching NetworkTransformChild but it doesn't seem to do what I want, and absolutely nothing is helpful on that
It's incredibly inconvenient that this doesn't seem to be supported whatsoever
Do you guys recommend "Unity Gaming Service" for work on cross platform stuff?
Hey guys, has anyone used SteamP2P with MLAPI?
I've imported the packages with no errors, and I can use some scripts (like adding the Steam p2p transport script to a gameobject), but I can't do "using MLAPI.Transports.SteamP2P;" or "using Steamworks;" to use the steam matchmaking functions in my scripts 😦
However if I edit the SteamP2P transport script I can clearly see the "using Steamworks" implementation and the "namespace MLAPI.Transports.SteamP2P" 😕
Maybe it's because I installed SteamP2P manually via disk, and not via git, but installing it via GIT throws me this error:
[Package Manager Window] Cannot perform upm operation: Unable to add package [https://github.com/Unity-Technologies/multiplayer-community-contributions/tree/master/Transports/com.mlapi.contrib.transport.steamp2p]:
Package name 'https://github.com/Unity-Technologies/multiplayer-community-contributions/tree/master/Transports/com.mlapi.contrib.transport.steamp2p' is invalid. [InvalidParameter].
Which version of MLAPI are you using?
0.1.0
I also tried using the git url in the steam transport readme (https://github.com/Unity-Technologies/multiplayer-community-contributions/blob/master/Transports/README.md) but still didnt work, giving me a different error:
[Package Manager Window] Cannot perform upm operation: Unable to add package [https://github.com/Unity-Technologies/mlapi-community-contributions.git?path=/Transports/com.mlapi.contrib.transport.steamp2p]:
Cannot checkout repository [https://github.com/Unity-Technologies/mlapi-community-contributions.git] on target path [Transports/com.mlapi.contrib.transport.steamp2p]:
Error when executing git command. error: pathspec 'Transports/com.mlapi.contrib.transport.steamp2p' did not match any file(s) known to git
(I took the url, removed the "enet" at the end and added "steamp2p", I'm not sure if that's how it was supposed to do, but I think it should work)
Okay, it worked perfectly... What did I do wrong? 🤔
I found a topic in the Unity Forum where I downloaded a demo, which uses both MLAPI 0.1.0 and SteamP2P 1.0.0
funny enough you also replied to the topic, but the link you gave is the link that I used, without the "#release-0.1.0" at the end
Can I use Netcode for GameObjects in my Nintendo Switch game?
So I have a simple network game but it only works locally but I am pretty sure it should work between other PC's as well if anyone wants to please look at my code and tell me why i cant connect to another PC . I have also found something that might cause this bcs I think my port is closed on my router but I currently have no way to open it havehttps://pastebin.com/Mpb4g3Cd
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I'm no expert but for my custom UDP implementation I had to use "NAT punching", it's not super complicated but you'll need a master server to organizing connecting the game server to the client (and vice versa). There is also some techniques where you just "guesstimate" the external/public port based on how routers usually assign their external ports in NAT.
Note that for some users on restrictive routers this will not work, and ideally you'd relay (forward) all your traffic through the master server.
But at that point I'd look into using something like Steam P2P or Photon (i have no experience with either)
with master server you mean something like a dedicated server right
cuz I dont have that I am trying to host the game on the players PC
(Using Mirror) Does anyone know why I'm getting this error?
NullReferenceException: Object reference not set to an instance of an object
ArenaManager.OnStartClient () (at Assets/Scripts/Networking/ArenaManager.cs:36)
Mirror.NetworkManager.StartHostClient () (at Assets/Thirdparty/Mirror/Runtime/NetworkManager.cs:520)
Mirror.NetworkManager.FinishStartHost () (at Assets/Thirdparty/Mirror/Runtime/NetworkManager.cs:499)
Mirror.NetworkManager.StartHost () (at Assets/Thirdparty/Mirror/Runtime/NetworkManager.cs:448)
Mirror.NetworkManagerHUD.StartButtons () (at Assets/Thirdparty/Mirror/Runtime/NetworkManagerHUD.cs:72)
Mirror.NetworkManagerHUD.OnGUI () (at Assets/Thirdparty/Mirror/Runtime/NetworkManagerHUD.cs:38)
I tried doing it on the player object itself, but the host doesn't seem to have authority over their own player?
Hello, I'm trying to debug my MLAPI game made with SteamP2P. Is there a way to debug clientside from the editor? I can connect from another game via steam to the client, but I can't join a game with the editor's game, and uploading the build every time seems so time consuming...
Hey I'm following this tutorial https://www.youtube.com/watch?v=93SkbMpWCGo&t=328s(step 7) and I'm getting this issue where the camera and player glitches out when another person joins ive been triyng for so long to fix it but im getting very annoyed i could vc if you need to show you the whole problem
Get your next game design project organized - Sign up to Milanote for free: https://milanote.com/blackthornprod0621
Udemy Multiplayer course: https://www.udemy.com/course/beginners-guide-to-multiplayer-game-development-in-unity/?couponCode=86D7C0073D7CD59B6C07
0:00 - Intro
0:3...
Check your windows firewall rules, I think because your unity code can be sensitive, unity by default might have a "block all external traffic" rule (easiest way to test is to (TEMPORARILY) disable your windows firewall
No, there would be a player that hosts the game, a player that wants to connect to the host and a "helper" server that connects the two players together (outside both players NATs). But really, if it's difficult, I'd recommend looking into a third party solution such as Steam P2P or Photon. They offer this "helper server" for free, and will even relay your traffic for free (up to a point) if NAT traversal fails
Already done, I can easily connect with Unet transport layer (also I have already done port forwarding)... I think my problem is likely to be in my code. The "join lobby" callbacks never gets called T.T
What happens if a player fails to connect with Steamp2p (and mlapi)? The callbacks gets called if the player successfully joined the lobby, otherwise what happens? How can I debug that?
Mnn sorry I don't have any experience with Steam P2P or MLAPI
Will cloud save will be paid after beta?
How many players can be played at once in netcode?
I don't believe there is a hard limit to the amount of connections, you can adjust that field. There is a practical limit where the lag becomes bad
Just downloaded the Unity Lobby demo for the new Unity Game Services, anyone else having issues with it? This is me running the game from the main scene.
oh wait think i need to set up my project Id for this one.
Tried this because I'm having problems in the project i'm currently working on tho
here's the error I get when trying to create a lobby
"Unity.Services.Lobbies.LobbyServiceException: HTTP/1.1 401 Unauthorized"
Anyone know what that means?
sorry if its obvious
using System;
using System.Collections.Generic;
using Unity.Services.Authentication;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using Unity.Services.Lobbies;
using Unity.Services.Lobbies.Models;
using UnityEngine;
public class LobbyManager : MonoBehaviour
{
public string environment = "production";
async void Start()
{
await UnityServices.InitializeAsync();
try
{
string lobbyName = "Custom Game Lobby";
int maxPlayers = 16;
// Lobby options
CreateLobbyOptions options = new CreateLobbyOptions();
options.IsPrivate = false;
// lobby data
options.Data = new Dictionary<string, DataObject>();
options.Data.Add("Gamemode", new DataObject(DataObject.VisibilityOptions.Public, "Race", DataObject.IndexOptions.S1));
//lobby player
string playerId = AuthenticationService.Instance.PlayerId;
Dictionary<string, PlayerDataObject> playerData = new Dictionary<string, PlayerDataObject>();
playerData.Add("Name", new PlayerDataObject(PlayerDataObject.VisibilityOptions.Public, "Steve"));
Player player = new Player(playerId, null, playerData);
options.Player = player;
Lobby lobby = await Lobbies.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
}
catch (Exception ex)
{
Debug.LogError(ex);
}
}
}
heres my code :p
Make sure that you have activated the Lobby Service in your Unity Dashboard
Hey thanks, are you referring to this one? It's already switched on for the project I'm using. I'll try turning all the others on tho. ^_^
Yep that's the one
lol after turning it on and off again i've now got a different error
heres both of them @sharp axle
Oh, make sure you are logged in with Unity Authentication Service
I think it's AnonomousLoginAsync() or something like that
alright, I'll have a look into that. thanks again ^_^
thanks, that actually did get me further
but god damn, a new one
I probably should try and do more research, just haven't been able to find much documentation on setting things up for a lobby from the top 😦
Unless theres some documentation you'd recommend, I might try and take apart the unity lobby example
seeking sanity check from the experts 🙇 : I'm working on a moba/td style game with some base building/resource management for up to 4 players. I was thinking of using PUN. Player resources and stats would be synced props, player "commands" (e.g. unit move to position) would be RPC's, and units/enemies would sync their positions, health, maybe a few other things from host to clients (because Unity is not deterministic so things will drift out of sync otherwise). Does that all sound reasonable? Any resources or recommendations that would help me out?
From Photon, go for Fusion (or quantum if you have a budget, as you can do determinism for that type of game)
Being a new project, no point in sticking to PUN, which is being phased-out into maintenance mode
thanks will take a closer look -- obviously open to any tech at this point -- quantum seems like the right tech for me, but can't justify the cost
and again if my outline sounds off any direction welcome 🙂
Punch through NAT, if you have a server to act as a middle mad, both clients could send a message to the server, the server then sends a message back with the other client's IP and port and then the clients can then send a blank message that will then put the client's credentials onto the list of allowed IPs.
I am having a bit of trouble understanding this if anyone could pls help me explain to me the last sentance with what he means the client credentials onto the list of the allowed IP's
like how would you do that
what list
it's not 100% clear from the sentence, but the way NAT punching works is that
- Alice's data is blocked by Bob's firewall
- Bobs data is blocked by Alice's firewall
- Alice sends a message to Sandy (the middle man) with her port 1234, Alice now accepts data on port 1234 to receive the reply from Sandy
- Bob also sends a message to Sandy with his port 4321 and listens for a response on that port to hear the reply
- Now Sandy knows, Bob can receive data on port 4321 and Alice can receive data on port 1234.
- Sandy then tells Alice: "Hey, Bob is able to receive data on port 4321, try sending a message to him there!"
- Then Alice sends Bob a message on port 4321 and listens for a reply, Bob receives the message because he was listening on that port!
- In the meantime Sandy also sends a message to Bob, "Hey, Alice is listening on port 1234! Try sending your data there!"
- So Bob sends a message to Alice on port 1234, and now both Alice and Bob can send each other messages.
They fall in love, get married, have kids and live happily ever after. And that's how NAT punching works.
I think the specific list of allowed IPs is a precaution because people could be randomly sending you data, so in this case: Sandy would have to tell Alice not only the port to contact Bob at, but also what Bob's IP is to expect the reply from. Otherwise it could be Charlie who is a nasty hacker.
Hey i need help with my project.
Ive done a bit of rework today and fixed some issues but for some reasons player cant see weapons anymore, my "animation" is not showed and even the sneaking dont work and i dont fucking know why
i have seperated the player model (monkey bean 1) from player_1 so i can scale it without have issues with my camera
i have changed nothing to the weapon code or like this but i dont work anymore
this is my prefab
players just see their own sneaking, weapon changed (...
but dont see if other player does
thanks that really cleared it up for me ,great explanation also is the B for braindead?
btw your game looks sick I wishlisted it
ive made a animation with this code but other people cant see the bones moving, any clues?
are you sending the new position of the bones to the clients
I dont really know. But ive used the same script for rotation weapon and stuff like this and it work
so i dont know why it dont work to the bones
how i can send it to the clients
i guess im not doing it
Thanks!!
Yes your game looks good but u should work on your graphics in my opinion.
More tree variation
more decoration in the background
the trees also looks a bit "glowy"
can you tell me how i can do this? @vast apex
yeah! I have to admit as a programmer too much time is spend coding, and not enough time is spend on 3D assets 😢
U could buy some on fiverr
they are not very expensive and on your state maybe you can try kickstarter to get some money
what are you using for your network
Dont release the game as it is it work on it more look very good yet
what api
mirror
Thanks for the feedback and advice guys, appreciate it! I think I will definitely get somebody from fiver to help me with the graphics 👍
oof, the time everything takes
Yes. But in the end you can have a very cool game
https://www.youtube.com/results?search_query=how+to+polish+your+game u should watch many of these videos
and in the end this could be useful for you https://www.youtube.com/watch?v=ht6xx9en-ZU
How do you make a great store page for your indie game on Steam to get more wishlists, downloads and ultimately sales? Professional indie game marketeer Chris Zukowski shares his best marketing and optimizations tips and tricks to make sure your Steam page gets the visibility it deserves. This video is a must watch for everybody who wants to suc...
cool yeah! i'll check it out, it would be especially good to raise some money with a kickstarter, even a little bit..
if you try kickstarter maybe it could be useful to make a very good trailer of your game or buy it
- write a good text or buy some from a text writer so you get many clicks / Money
u cant avoid costs and 3d models are very hard to make in my opinion.
im not as far as you in my game development but i already spent money on a model cause i cant do it myself and i think its very boring.
If you want I can give you the offer to give you some more detailed feedback.
Just ask if you want it to
Some playtesters are always good in my opinion you can also asks friends or something like that.
U can setup a google document with several questions to get good feedback also
Can anybody help me? Im using Mirror and have a code for a bone rotation. It works fine but u cant see the head rotation of other people and that confuses me
sneaking isntalso displayed to other players so the problem is may my player model or my prefab
maybe somebody know about prefabs and can help me
The references in my script are not working.
Im having trouble with pun can someone dm me so i can show you the problem its hard to explain
How do I Install netcode ? From package manager or from GitHub?
There's a mirror discord server, a good place to get help for mirror stuff, probably faster than here
https://docs-multiplayer.unity3d.com/docs/migration/install If you mean Netcode for GameObjects
U Are Right. Thank you.
Im pretty Sure its a Reference Problem Not a Mirror prob
I want to count who killed who with Photon Pun how can I do that
@weak plinth https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/pun-basics-tutorial/player-networking
You should go through all the "Basics Tutorial", but you should find your answer here..
Photon Unity Networking framework for realtime multiplayer games and applications with no punchthrough issues. Export to all Unity supported platforms, no matter what Unity license you have!
How do i prevent spamming serverRPCs?
I just want to send the users Input via ServerRPCs. But sending it in the Update() method just looks like spamming
packets to me...
are you happy to wait a few frames between?
could always have a frame counter
wait till you hit 5 or so frame then send the data
I would rather just have a fixed time interval that is checked every frame.
Waiting for frames means that different clients will have vastly different packet frequencies
Interesting would be a notification on tick start. Hm. Maybe thats an idea. On tick start: ClientRPC -> Client Checks latest Input -> ServerRPC with Input
yeah a request to the clients wouldn't hurt
I wonder if you can modify the network variables so they send packets between each other more slowly?
if you're using the new input system you could also take advantage of the delegate structure to slow things down too
I dont care about that. They are based on the tick rate. And even 60 packets per second is def fine.
But 400 FPS means 400 input packets per seconds.
But clients cant write to network variables as far as i know
i'd just use a coroutine then and wait for seconds real time
or, use a network variable, i'd imagine it would handle all of that automatically
Thats just artificial lag
It would but the client cant write to it
you should be able to change ownership
and the owner settings of the network variable
Let me check that out. It would solve my problems...
wait, did they remove write permissions?
Can i change the owner of NetworkVariables or do i have to change the owner of the parent NetworkObject?
I swear you could do it back in 0.1.0
I wonder if setting the ownership of the network object would work
Ill try that brb
alright gl ^_^
Nope. "InvalidOperationException: Client can't write to NetworkVariables"
wow
I cant imagine that the only way to get real time input to the server is to bombard it with Rpcs
Unless they handle that internally already
oh wow "In the newest implementation they have chosen to remove the ability for clients to change NetworkVariables. You have to use RPC's instead. You can check the NetworkTransform and Samples/ClientNetworkTransform scripts for a way to implement client writing."
Ive written my own UDP based mini game in Java so im a bit conscious about my bandwidth usage...
so they did remove writing to network variables from a client.
Are you trying to send an input over the network to move the player on the servers end?
But i want to just write into a buffer that will be eventually consistent for the server...
like what exactly are you trying to achieve?
You might be able to translate the player on the client machine
and then if the player moves too far you could rubber band them if it seems hacky
thats what ive done at least for what my game needed
I have a 2D Object that is spawned by the Server. I then let a client reference that GameObject.
The client should be able to move this Object with his input.
My 2D Object has a NetworkTransform component
Oh dope
so if you move the object from the clients perspective it should already sync across the network
But even if i change the ownership of said NetworkObject, the Object does not move.
Did you spawn the object in from the server side?
using the network manager to spawn in the prefab?>
This is what i do:
private void Start()
{
_clientId = GetComponent<NetworkObject>().OwnerClientId;
if (IsServer)
{
_tank = Instantiate(tankPrefab).GetComponent<Tank>();
var networkObject = _tank.GetComponent<NetworkObject>();
networkObject.Spawn();
networkObject.ChangeOwnership(_clientId);
networkObject.AutoObjectParentSync = true;
networkObject.DontDestroyWithOwner = false;
var clientRpcParams = new ClientRpcParams
{
Send = new ClientRpcSendParams
{
TargetClientIds = new[] {_clientId}
}
};
ReferenceTankClientRpc(networkObject.NetworkObjectId, clientRpcParams);
}
}
[ClientRpc]
private void ReferenceTankClientRpc(ulong tankId, ClientRpcParams rpcSendParams = default)
{
_tank = NetworkManager.Singleton.SpawnManager.SpawnedObjects[tankId].GetComponent<Tank>();
}
I just spawn it, change the ownership to a client and then let this one client reference the Object on his side.
Via the Objects network ID
Is there another way to send the Rpc to only one specific client?
I'm assuming thats the correct way to do it tbh.
Otherwise everyone would reference only the latest tank...
I just send it to every client because the needed to know a few details about the other players anyway
and then only set ownership if the id matched up with the client
god my projects now not even work for me to reference things lel
Hm. And everyone could then check locally for the owner id. But the referencing itself works.
The _tank var is not null anymore and Translate/Rotate are called as well. Just nothing happens:
private void ClientSideUpdate()
{
if (_tank == null)
{
return;
}
var forward = Input.GetAxis("Horizontal");
var rotWard = Input.GetAxis("Vertical");
var tankTransform = _tank.transform;
tankTransform.Translate(tankTransform.forward * (forward * Time.deltaTime * 5F));
tankTransform.Rotate(0, 0, rotWard * Time.deltaTime * 5F);
}
probs shouldn't have updated to the new version of "mlapi"
Didn't intend to create a competitive free for all arena game.
for reference I've been working on a 2D game too
and I just used the network transform to do all of the magic
however, this is in an older version of mlapi
give me a little bit
now I'm super confused XD
Yeah but does the client call the transform methods or do you just send Rpcs to the server so that it calls the transform methods
On the Object that has the NetworkTransform component
Its automatic
just update the transform on the client
and it should send across the new position
😦
and it has a delay between positions sent
And it interpolates. Thats all nice but why does it not work for me then 🥲
Ill try one more thing
Fun fact: If i start as Host then i see movement...
[ServerRpc(RequireOwnership = false)]
public void SpawnPlayerServerRpc(ulong clientId, int deviceId, Color colour)
{
Unit player = Instantiate(prefab, parent);
NetworkObject no = player.GetComponent<NetworkObject>();
no.SpawnAsPlayerObject(clientId);
var netId = no.NetworkObjectId;
SpawnPlayerClientRpc(netId, clientId, deviceId);
player.networkColourHue.Value = Random.Range(0f, 360);
player.onUnitStatChange += (u) =>
{
if (u.stats.currentHp <= 0)
{
UnitDeathServerRpc(netId);
}
};
}
[ClientRpc]
private void SpawnPlayerClientRpc(ulong netId, ulong clientId, int deviceId)
{
NetworkObject no = NetworkManager.Singleton.SpawnManager.SpawnedObjects[netId];
Unit player = no.GetComponent<Unit>();
if (NetworkManager.Singleton.LocalClientId == clientId)
{
PlayerInputHandler.instance.AddPlayer(player, deviceId);
}
}
alright lets take a look at mine :p
got I coded this a bit ago :p
Oh. Thx to you i just discorvered networkObject.SpawnWithOwnership(_clientId);
dope :p
Oh.
You might need to do it all in a ServerRpc?
Thats what I did at least
Clients, when a device is plugged in (local multiplayer) I make a request to the server to spawn in a player
Hm. I thought
if (IsServer)
{
Would suffice
Ill try that
Oh also, its happening in start too... So shit might be happening before the network even starts... which confuses me as to why you actually are able to spawn in prefabs
So like this:
private void Start()
{
_clientId = GetComponent<NetworkObject>().OwnerClientId;
if (IsLocalPlayer)
{
RequestSpawnServerRpc();
}
}
[ServerRpc]
private void RequestSpawnServerRpc()
{
_tank = Instantiate(tankPrefab).GetComponent<Tank>();
var networkObject = _tank.GetComponent<NetworkObject>();
networkObject.SpawnWithOwnership(_clientId);
var clientRpcParams = new ClientRpcParams
{
Send = new ClientRpcSendParams
{
TargetClientIds = new[] {_clientId}
}
};
ReferenceTankClientRpc(networkObject.NetworkObjectId, clientRpcParams);
}
Maybe even OnNetworkSpawn() instead of Start()
I got you
public override void OnNetworkSpawn()
{
//spawn player server rpc
}
yeah lel
onto it at the same time XD
wonder if you can help me back tho, any idea what these errors are?
this is after trying to update to the newest version of netcode for gameobjects
Looks like some Rpc tries using null fields or values.
Try running the other side in Unity. It might give you a better idea of what could be null
you know what, i have a theory and you might have saved me
Still not moving...
private void ClientSideUpdate()
{
if (_tank == null)
{
return;
}
var forward = Input.GetAxis("Vertical");
var rotWard = Input.GetAxis("Horizontal");
var tankTransform = _tank.transform;
var isOwner = _tank.OwnerClientId == OwnerClientId;
Debug.Log(isOwner);
tankTransform.Translate(tankTransform.forward * (forward * Time.deltaTime * 5F));
tankTransform.Rotate(0, 0, rotWard * Time.deltaTime * 5F);
}
This prints True
So i know that:
- I have the reference of the Object
- I am the owner of the Object
And it works in "Host" mode
damn 😦
But this works...
private void ClientSideUpdate()
{
if (_tank == null)
{
return;
}
var vert = Input.GetAxis("Vertical");
var horiz = Input.GetAxis("Horizontal");
SendMovementServerRpc(vert, horiz);
}
[ServerRpc(RequireOwnership = true)]
private void SendMovementServerRpc(float vert, float horiz)
{
var tankTransform = _tank.transform;
tankTransform.Translate(tankTransform.forward * (vert * Time.deltaTime * 5F));
tankTransform.Rotate(0, 0, horiz * Time.deltaTime * 5F);
}
At least in know now that the NetworkTransform does its job
Wait have you got it working?
Yes but not the way i want. Now i send an Rpc every time Update() is called
And the Server then changes the transform
Ok so there is something called a ClientNetworkTransform
Wait wot
is this a component?
lol, my game is broken by one of the issues you got now that they removed clients writing to network variables
wonder If i'm going to need that too
In the package description there is an example implementation for client authoritative network transforms.
But i think ill just go fully server authoritative.
I just need to find out if packets are automatically batched or if i have to figure out a way to
prevent packet spamming.
wtf the documentation says I can still do this ```cs
private NetworkVariable<float> myFloat = new NetworkVariable<float>(new NetworkVariableSettings {WritePermission = NetworkVariablePermission.OwnerOnly}, 5);
wait wot
Huh. Does this work?
looks like my game might be broken now too when it comes to movement
Because i have a custom serializable UserInput class that could be shared like this.
oof
they've deprecated it but forgot to update the documentation
looks like a lot of client control has been removed in favour for rpcs
I see
which is kinda annoying now that I've made my project based on an older way of thinking
got this explains my confusion so much XD
What is the best way to get real time input sent to the server.
Calling an Rpc every Update() seems like a bad idea as it bombards the server
with packets. Are they batched internally already or do i have to think of my own solution?
PS: Using client authoritative NetworkVariables was my first idea but clients cant write to them anymore.
well you're going to encounter a bit of nasty delay if you send the players input
i'd recommend sending the players transform
then doing interpolation on the server
even if its just the players position :p
I might be about to encounter this issue tho
lets hope my transform component works still
Oh shit I am 😦
Clients no longer control the component :(((((
@coarse goblet Thanks for pointing out the client network transform
that actually fixed my game ^_^
its almost working again
With how things are I'm now sending data every fixed update frame so the animations work
so this is a bit shit
however because its animations I can delay it all
FixedUpdate is about 50 times a second so that is very frequent, you can most likely get away by sending it only 10 times per second or only sending a new animation state when the state has changed
On a 64 tick server this would be quite bad. Also: Are Rpcs sent async or does it block the frame.
Not sure why that would be bad, if something doesn't change so constantly then it would be a waste to send so many updates
(Using Mirror) Does anyone know why this code causes this error, and only on the client? It seems that the client can't access their own object in OnClientConnect
System.NullReferenceException: Object reference not set to an instance of an object
at ArenaManager.OnClientConnect (Mirror.NetworkConnection conn) [0x00011] in D:\Github\Artifacts-of-Punishment\Artifacts of Punishment_clone_0\Assets\Scripts\Management\ArenaManager.cs:27
The host gets My player is NetworkPlayer [connId=0] where the client gets the error
On client connect is too early to be referencing the identity or player prefab instance, it works on host because all host stuff doesn't actually go over the network because they're already on the server
Onclientconnect is simply when the client connect attempt was successful, nothing game object related has been spawned yet for the other players
So would I just have to do that in some other script?
Onstartlocalplayer on player prefab
I just got back from a long-ish break and OnStartLocalPlayer doesn't seem to exist
it's an override
Oh yeah, it didn't get intellisensed, so I assumed it was just a void
Just how important is it to minimize bandwidth usage? I find myself worrying about it with every line I write
Is it best to have the clients do all the math and then send the answer back to the server, or just send the raw numbers to the server, and have it do the math? What about moving characters? Should I have them move on the server, or have them move locally and wait for the server to sync everyone else with that? Animations? Particles?
We're using Mirror (although that shouldn't really be relevant to this) and anticheat isn't a concern for our game
If cheating doesn't matter then make the calculations client side and send result to server
I'm wanting a p2p networking solution that's free and am looking at photon bolt. Would this do what I want?
I don't need to use photon cloud do I?
How much should I care about bandwidth though? There are a few things you wanna avoid with non-networked code, but most of it can be handled by modern computers without issue
We aren't considering individual CPU cycles and stuff at this point, so is the internet at the same point? Or do I need to really think about that
Ideally you want to minimize the amount of information sent over the wire
Even if the tradeoff is a little more cpu usage
but its really a game of balancing when it comes to server auth stuff
But if it's all client auth with no care for cheating then you don't need to worry about that part
Np
Hello, I'm trying to connect a local database to unity, but every time it tries to use the sCon.Open() it crashes, throwing that the conection got rejected from the destiny.
Does someone know something about it?
Players usually don't change their input 400 times per second, so instead you can compare the last input to the current input and only send a input packet if the last input if different from the current input. Then program all your clients to repeat the last received input packet for each frame. Note that with UDP you might miss a few packets now and then depending on the connection quality, so I'd recommend sending an input packet every 250ms or "anyway" just to be sure (250ms is years in computer time anyway).
or add some sort of protocol that "AWK"s your input packets (also make sure to ignore any older packets then the last one received to avoid out of order inputs)
RPCs get queued up and sent in batches. You can also set the Delivery to be either Reliable or Unreliable
I asked the Devs and they told me that the packets get batched anyways. But i'll consider this approach.
Hey guys how can I check if a connection was successful or if a client is connected on a server in MLAPI?
Hey! ummmm how could i make a simple meeting system for my game? (like in among us)
Hey, im wondering what networking system the popular mobile games like clash of clans, lords mobile are using? Maybe someone know and want to share this information. What i know is that they have database to store players data and thats all. They've own networking system?
I'm not sure what netcode they are using but I do remember them being all in on the AWS backend
There's no public "network system" for them, they all develop their games without engines or they create their own engines. They probably use sockets or some higher level of networking, built by them. So everything's private.
I am trying to make an online game but when I host a game and then join with another PC Ic an only move as the host the client cant move this is my code I am using to move. This script is on both players
https://pastebin.com/E1n8Ymuf
I am new and learning mirror so any help would be welcome
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Lords Mobile is using Unity as game engine
Yeah, not supercell. Everything depends on the game, and there's no general rule, but most of the times indies goes for Unity and some common solution like Photon or UNet, while big companies make everything from scratch.
You're focusing on the wrong things in my opinion. There are many different networking solutions and it's up to you to research which ones are suitable for the game you're trying to make. The big companies most likely don't use off the shelve solutions, but even if they did how are you sure that's the one you need without researching?
I can tell you however that all of them claim to make networking easy but this is very relative. There' still plenty of work that needs to be done, and you have a big responsibility to understand how they work to get it working like you need it to
I'm trying to have one instance of a project being played in WebGL streamed to another browser (probably also running Unity WebGL). Any idea how to do that? I think it would be with something like WebRTC. Is there an easy way to do that? Would just need to be the video, wouldn't need to be interactable (although if possible that would be even cooler).
Unity has a WebRTC experimental package. But it looks like it doesn't support WebGL
Uhm? I'm confused. https://docs.unity3d.com/Manual/webgl-networking.html
WebGL does not allow direct access to IP Sockets, but you can use WebSockets or WebRTC (the two most common networking protocols supported by browsers) to get around this.
Maybe their package doesn't but WebGL does support WebRTC
I know it is possible to do, was more wondering if anyone has done it and/or knows the easiest way to do it
I was referring to this
https://docs.unity3d.com/Packages/com.unity.webrtc@2.4/manual/index.html
Yeah, the article mentioned that
Unity does not have a built-in API that allows you to use WebSockets or WebRTC, but you can use a JavaScript plugin to implement this. You can find plugins that implement WebSocket networking on the Unity Asset Store.
How to send request to server?
From different clients
If I trying to call Door open function from other clients
I gets
"Only owner can invoke ServerRPC that is marked to require ownership"
Its safe?
That's what you'll need to use if the client is not the owner of said object
I'm getting the following error: (Full text: https://www.toptal.com/developers/hastebin/awahojucaw.sql)
Disconnecting connId=0 to prevent exploits from an Exception in MessageHandler: NullReferenceException Object reference not set to an instance of an object
at Mirror.NetworkIdentity.OnStartServer () [0x00085] in D:\Github\Artifacts-of-Punishment\Artifacts of Punishment\Assets\Thirdparty\Mirror\Runtime\NetworkIdentity.cs:659
From line 25 here. Both of the debug logs run and give the expected result, so I'm not sure what's causing this
I'm calling it from here on the client (although playing as host): CmdSetUpLocalObjects(NetworkConnection.LocalConnectionId);
Anyone in here ever experiment with reconciliating rigidbodies in physx?
I've found that it works fine with a car on 4 custom wheel colliders, but the second the car body hits another collider, (like the front bumper hitting a wall or terrain), you get mispredictions up the ass
This is an ongoing issue for me, 6+ months now, and yes, I've quadruple+ checked that everything matches between scenes. The cars, maps, etc are 100% identical. There's nothing wrong with my reconciliation algorithm, otherwise I wouldn't be getting perfect predictions while the car is driving on 4 wheel colliders
Hi guys, i'm a bit lost on something...
I just started to create a project oriented for multiplayers, but tipping Unity multiplayer game, sent me to MLAPI, and follosing some links i landed on Netcode for gameobjects.
so i don't understand witch one should be used
any clue ?
it seems that MLAPI is finally the old one, and Netcode for gameobjects the right choice ... am i right ?
MLAPI was renamed "Netcode for GameObjects"
@austere yacht ok, good, i'm on the right way, thanks
Has anyone done anything with client side predictions?
I just a few questions based on a few bugs im having with it
@blissful kayakRigidbody or character controllers
@teal obsidian physx
Is it a vehicle or what
physics based characters
Physx doesn't like to be reconciliated if theres collisions involved
when there is any latency my characters freak out
I'm in the process of trying to find a workaround
yeah
physx hates to be reconciliated
Yes Im currently using mirror for the base
yeah I've never worked with mirror or any third party services so I'm no help there
but you have done physx client side predictions
I've done it with wheel colliders
it still shits itself when the actual body collides with another collider such as when the bumper hits the terrain
as far as I'm concerned its impossible when you have real collisions going on
right, well thanks anyway. imma keep trying
I just posted this about an hour ago
you can try commenting your issue there to see if it gains any traction
thanks
I've tried making posts like this in the past, didn't get any feedback from unity staff
I wouldn't expect much
As for your situation, you can either
A.) Send the inputs to the server, don't predict on the client, and just have the server send new position/rotation data for your players
B.) Not use rigidbodies for your characters
@teal obsidian this is what I have been basing mine off. It is with 150 ping and no interpolation.
they are different interactions events
you can see the cubes spazz out when they collide with each other
tell me you see that too
on the client part
Yes I do see that but am expecting that with moderate ping and not interpolate. so for my game I dont mind as much as input lag, especially when I try to smooth out the movement
can someone who uses Mirror explain to me what I'm doing wrong? I'm trying to spawn a bullet such that both clients can see it
I have code on my gun script that extends monobehavior
private void shoot_primary_ammunition(){
player.spawn_object_on_network(ammo, reticle, bullet_spawn_point);```
it calls a function on my player script, which extends networkbehavior
[Command]
public void spawn_object_on_network(GameObject obj, GameObject reticle, Transform bullet_spawn_point){
GameObject fired_bullet = Instantiate(obj);
fired_bullet.transform.position = bullet_spawn_point.position;
fired_bullet.SetActive(true);
// raycast
Vector3 target_point = Camera.main.ScreenToWorldPoint(reticle.transform.position);
Ray ray = Camera.main.ScreenPointToRay(reticle.transform.position);
// launch the bullet towards the raycast
fired_bullet.GetComponent<Rigidbody>().AddForce(ray.direction * fired_bullet.GetComponent<Projectile>().speed, ForceMode.Impulse);
//spawn the bullet on the server
NetworkServer.Spawn(fired_bullet);
}```
the variable I call "ammo" is a bullet prefab with a network transform attached to it
yet when I call this function, nothing happens, and the bullet doesn't appear for either client
what am i doing wrong?
@south palm and its not appearing in the hierarchy?
yeah. someone on the mirror discord said it's because I can't pass prefabs to the server?
so I'm trying to instantiate from the list of registered prefabs and see if that works
@south palm yea if the object is not in the registered prefabs it will not spawn, but it should give u an error.
Also, from you code it might not spawn the object in the correct position, as from my experience the network.Spawn() just instantiates the object on all clients
how do you put it in the correct position then?
and it is in registered prefabs, but the way I have it coded here it's not spawning on either client
do you have a server and then two clients connect or a host and a client?
I changed the instantiate code to this:
GameObject fired_bullet = Instantiate(nm.spawnPrefabs[1]);```
and it's still not spawning
two clients and a server
ok, so is the only play to play the game is through only builds or can the edit, be the server or a client?
yeah I play one client in the editor, then I create a windows build and a linux server build
and i play the other windows build as an exe
and I upload the server build to my server
yep ok, and while u play in the editor nothing spawns in the hierarchy?
yeah nothing
it seemingly calls the function because there are no errors or warnings, just whatever debugs I put in the client side
can u see debugs on the server in the terminal?
debugs I put in the [command] function don't appear in the terminal
debugs I put in any other function appear clientside
I havent worked with a dedicated server, i have a host a clients
hmm
can u do a developer linux build?
you mean a development linux build?
yes
server or client?
my server build is already a development build
unless u can have windows builds that can connect to the editor as the server
and debugs don't show up in the terminal output
Hi, i'm trying to add client side prediction / server reconciliation (with physics) to my multiplayer game.
Sometimes the player is juddering when the local-state and the server-state is too different.
Another problem is jumping. If an old input-state is rewinded, the player is jumping again if the jump-key was pressed in the old state.
Can someone tell me how to fix this, or what i'm doing wrong?
@tender mothYou should reconciliate every tick regardless of client/server position of the player
@teal obsidian ok, i will try. But how to handle jumping? If i rewind every tick, i will alwasy jump 2 times...
then your code is probably wrong
because that shouldnt happen
your reconciliation code should be running the same stuff as the normal simulation
so reset player position, rotation etc, then check if your player pressed jump that tick, then check if the player is currently grounded, etc
you don't re-use anything except for inputs
hm so this means if i press jump - im jumping - but when i rewind the input a few frames later, im not grounded so i dont jump again?
its a bit of a brainfuck to try to explain it in laymans terms
but if the reconciliation works, then it should look as if nothing has happened
since you're simulating until the present tick
so at the end of the reconciliation event, you should end up exactly where you were before reconciliation occured
unless the client mis-predicted for whatever reason
Are you using rigidbodies or character controller?
rigidbodies
physx hates to be reconciliated just an fyi
especially if any collisions are happening
I got it working with a car since its basically a hovercraft with wheel colliders, but if I smash into something, it flickers and mis-predicts like crazy
other people like fholm and roystan claim to have gotten it working with collisions
hm ok ;/
if you have a proper rollback (that resets everything), it works, except enter/exit would be unreliable on clients
But the actual behavior of physics can be fully predicted, of course.
it flickers and mis-predicts like craz
This looks like something is done wrong.
I mean I've had the problem for 6+ months
joy looked over my reconciliation code for rigidbodies, said theres nothing wrong
works flawlessly as long as the RB is gliding on wheel colliders
no difference in position/rotation between client/server
Here's a "claim". What about Ragdolls?
Haven't tested, have no need for it