#archived-networking
1 messages · Page 103 of 1
i am not... i am sure of it
the method is supposed to destroy a game object but it isn't idk why
I wanna change the region by pressing a button
But I first need to disconnect from the old region and connect to the new one
And so on if I want to connect to other
Did you check whether whatever you passed into the method isn't null?
Maybe you can follow the code to see what exactly leads up to the null
yes the method checks if the local player is the targeted player and deletes an object
sure
Any idea on how to fix this, danny?
Fix what exactly? Are you sure disconnecting requires you to be a masterclient?
Thats what the error tells me
What are you calling?
private void ChangeRegion (string newRegion)
{
if (PhotonNetwork.CloseConnection = newRegion)
{
return;
}
"Only the master client can do this"
That syntax doesn't look right, but any reason to use that over Disconnect?
Idk
A guy on a thread made this script
And said it works
Not seeing references to CloseConnection?
When I hover over the CloseConnection it tells me why it doesnt work
Its in gray color
Share it with the rest of us
You are assigning a region to a CloseConnection method?
Might wanna double check the suggestion on the forum
But is the code that guy made good?
i think my current debugging question for the code i posted above is this : "in the game scene which is running, there's more than one controller (prefab), I want to change the team then use the die method ... (the die method works as follow : destroy the game object, then check what team it is in and based on that instantiate the prefab... i could post it if you want ) "... so my question is would I need a photon view to do it?
Comparing the return value of CloseConnection to a region doesn't make a lot of sense
@weak plinth Yea there is a decent chance network remove requires a photonview
I didn't use networkremove ... i used photonnetwork.destroy
Destroying networked objects works only if they got created with PhotonNetwork.Instantiate().
Are they Photon instantiated?
yes
Where are you calling it?
@spring crane I added the code and it gived me an error in unity when pressing a button to change region
Warning message: ConnectToRegion() failed. Can only connect while in state 'Disconnected'. Current state: Connected
UnityEngine.Debug:LogWarning (object)
Are you possibly trying to destroy the same object multiple times?
What are those Die methods doing?
@compact wigeon Well the issue seems pretty clear. Did you actually execute the disconnect line?
well, its in the code
public override void OnConnected()
{
base.OnConnected();
if (shouldChangeRegion)
shouldChangeRegion = false;
}
public void Die()
{
playerManager.DieAndRespawn();
}
yes same function in different prefabs
public void DieAndRespawn()
{
PhotonNetwork.Destroy(controller);
CreateController();
}
void CreateController()
{
Transform spawnPoint = J3aJ3y.GhostPlayers.GameScene.SpawnManager.instance.GetSpawnPoint();
PhotonTeam currentTeam = PhotonNetwork.LocalPlayer.GetPhotonTeam();
//2-4 player .... 1-3 ghost
if(currentTeam == null)
{
controller = PhotonNetwork.Instantiate(Path.Combine("Photon Prefabs/3 Spectator", "Spec Camera"), spawnPoint.position, spawnPoint.rotation, 0, new object[] { PV.ViewID });
}
else if (currentTeam.Code == 1)
{
controller = PhotonNetwork.Instantiate(Path.Combine("Photon Prefabs/5 Ghost/Ghost Prefab/", "Ghost"), spawnPoint.position, spawnPoint.rotation, 0, new object[] { PV.ViewID });
}
}
gameObject.GetComponent<GhostCode>()?.Die();
gameObject.GetComponent<Anotherc>()?.Die();```
So there is some potential to call the Destroy method several times
no cause the prefab has only of those and each of the statements say.. if the game object has this component then use the method die
Yea. Maybe add a log to DieAndRespawn method to make sure that is the case
@compact wigeon Just because the line is there doesn't mean some other line isn't preventing it from running. Make sure you are actually calling disconnect.
I just the the photonview.RPC
how would you call it?
it is working BUT AFTER I DO IT 2 TIMES
like i have to change the team 2 times for it to work
any ideas why that's happening
Your ChangeToEu and US and Asia are attached to buttons?
Yeah
I added PhotonNetwork.Disconnect(); in the start method
Maybe its working
Not working
That should Disconnect you from Photon's servers
There might be a delay
Not working
Log something in OnDisconnected
Because that will fire when you successfully Disconnect
Dealer's choice, but not inside it
guys I have found the cause of the problem... but i need help with it
the photon teams that i made are getting reset
when transitioning from the first scene to the game scene
or should i put a dont destroy on load?
that problem is solved but the main problem is sitll there
and I have one last question if you dont mind... If I suddenly close the run game mode (play), I get an error that the photon view is still in use and i sitll am acessing it, of course in the app, if it closes it is like a crash so there'd be no error HOWEVER just to be on the safe side, can I handle that error??
What's the best way to handle peer-to-peer networking?
With Photon, forum posts claim to be able to achieve p2p, but everything on their website advertises servers, and requires you to select server locations, and concurrent user plans, making me think that it would be limited by those servers.
Mirror is another one, but requires downgrading to at least 2019 version.
From anyone's experience, Is it worth using either of these, or is there a better option?
@crimson moat What do you exactly mean by peer to peer?
Various options include:
Player hosted servers (Mirror)
Peer to peer over relay (PUN)
Pure peer to peer where 20% of your customers can't connect due to network firewalls
Mirror requires downgrading? Since when?
Well I'd like to avoid firewalls for sure, but is the photon one limited by the concurrent users, if it's using a server?
because free is 20 max iirc
if mirror is just player hosted servers, that would also require firewall stuff, right?
They don't provide relay servers for free
Yea, but users that are willing to setup dedicated servers can generally figure out the port forwarding part
ahhhhh 
Mirror works best with Unity 2019 LTS.
Mirror generally works with all newer LTS versions too (i.e. 2020 LTS).
A lot of people ask us if Mirror is compatible with Unity 2021.0.1.preview or similar.
Unity's LTS versions are barely stable enough. We do not recommend running multiplayer servers with anything that's not LTS.
https://mirror-networking.gitbook.io/docs/general/recommended-unity-version
so none of those would be ideal
does something like Steam's networking with NAT punchthrough use servers?
I'm assuming it does
and I wouldn't want to be locked to steam anyways
maybe I'll just stick with paid servers, none of these seem good
Yea the NAT punchthrough is the thing that fails for some % of people
oh right
are there any others that do that besides steam? i'd like to check that out too
that's the only one I think would be an option beside just regular servers
I didn't expect that I'd have to go through all of this to get 2-4 players playing a party game online
For a not-so-serious project I would probably go for player hosted dedicated servers, since that allows all sorts of fun
For a casual party game just go for PUN
ok thanks
honestly I don't even know how to set up my ports lol, last time i remember it being a nightmare
Or Fusion depending on the gameplay
Well you don't have to deal with that with PUNs hosting
a fusion of things? or is fusion a networking solution
Photon Fusion
ok ill look at whatever that is
It should help a lot if you need higher quality networking features
Is there any easy explanations/documents how to sync objects and movements with PUN?
is fusion out ??
I believe beta builds are out now
Yes, public beta started around 1 month ago
You can download from the website (fusion docs section), and create the free app ids for testing
how do you show a list of the rooms hosted on the server with mlapi? anyone got any ideas?
how does the UNET ack system work?
MIRROR 42.2.12 IS LIVE ON THE ASSET STORE
Download: https://assetstore.unity.com/packages/tools/network/mirror-129321
ChangeLog: https://mirror-networking.gitbook.io/docs/general/changelog
how are the acks merged into the bitfield?
i keep getting a error can not instantiate before the client joined/created a room. state peercreated
Don't create network objects before joining a room.
Hi, I'm making an online chess game. When I added Photon fun 2, Figure a shape and changed position with the first player, it changed and the second player could not change position. How to get the second player to change position. Do I need to put a checkmark somewhere to make the statuette publicly available?
ive got an issue with animations over the network.
im using mlapi, the animations are syncing using just the mlapi network animation component.
this is whats happening:
https://streamable.com/mm1smp
the animations are played depending on the directional velocity of the players.
anyone have any ideas on how to fix this, or whats causing the issue?
im getting a photon error of the player controlling the other player when the 2nd joins
I know I'm not making a game with Unity, but I'm trying to make a phone app where you can select a time and day on a calendar and schedule a meeting with someone. I already have the information that is inputted to be be processed and sent to the person, but I need a calendar system for the app. So if Person A picks a day and time, then Person B can't do that time and day. I was thinking that I would need some kind of server to go about this, but not sure where to look into for this kind of thing. Yes, I know I could be using other things to make this but I'm most comfortable with Unity and already have most things done with this project. Any help would be greatly appreciated, thank you.
Yeah, you are going to need a server. I think the easiest approach would be to have a central server that clients would send the picked calendar date to. If the date is free, a "success" response is sent back and the date is marked as invalid. If the date has been marked as invalid, a "failure" response is sent back
Peer-to-peer isnt really an option here, because it could lead to different people picking the same dates, before you manage to sync the data across all devices
Plus, if you want to do peer to peer across the internet, you still need a central server for client discovery
gotcha thx for the input. Do you have any good suggestions for servers I should look into?
I was also thinking about maybe using Google Excel sheets as another method
w o t
You can just write another app, like a c# core console projecg, and include the same networking library you use in your unity app. Alternatively, use a blank unity app instead of a console project
If you want to DIY it, its literally just a TCP socket thats listening and accepting clients, then handling each client in a read-write loop
maybe you could read from a file that gets what days have been chosen and then block them out. if you choose a day then it adds it to the list and updates. idk lmaoooooo
If you write your own server app, you can use a real database, instead of excel
lmao I guessing the excel thing could work hm????? 
Yes, it could
But, using a database is better
The reason why is that it allows you a more structured way of storig data than just a list written to a file
It allows you to search the marked days more efficiebtly, by day or by user
You can extend it easily and keep a single file around, making it easy to backup
Theres no reason to not use a database
If you wsnt to keep a copy clientside, then feel free to use a simple file
But on the server, you should be using a real databasd
Hm databases just sound better lol. I'll have to figure out how to do all this stuff
You can look at EF Core, which is the database interaction solution for .net core afaik
It allows you to connect to pretty much any db i think
So you can stsrt off with s simppe db provider (such as sqlite) and move to bigger ones later (ms sql server)
Its just a nuget package that you have to ibstall, its really not bad
I applogise for my atrocious spelling btw. Mobile typing isnt my strong suit
hm alrighty. I'll try that. Do you happen to have any tutorials links to any of this? Also its all good, I could understand everything
I personally used the MS docs. Just search "ef core microsoft docs" and it should be one of the first links
I would folloe the quickstart guide in the docs
It should tell you how to connect to a db and define a model (basically, define what the stored data looks like)
All you should need is a single model class for storing which dates are taken, and by which user
I dont know of any good video tutorials, i didnt use them so cant vouch for them
Im sure if you just search "ef core .net" in yt you can find something
Much appreciated, thanks again for the help
Npnp
Hello, would anyone be able to help me out with a Photon issue? I'm kinda new to multiplayer programming, and I can't for the life of me figure out something seemingly simple lol
Posting actual details about any issues will get them attention much faster, don't ask to ask, just ask
Well, it's kinda a long description and I didn't want to bog up the discord haha, I'm using the Ready Player Me plugin to load in avatars from the built-in webview, it doesn't allow instantiating with PhotonNetwork.Instantiate, it works with a callback, so I have to call the spawn avatar method with an RPC and from there, i'm instanating the holder for the player, with photonnetwork.instantiate, and then trying to assign the avatar's parent to the holder, but it's not working out.
I'm hazy on how to assign an object to a single parent on all players, I tried using the photon view instance ID to get a reference to it, but it wasn't working, so at the moment, I attached a script to the avatar that searches the scene by name, and I'm naming each holder "Player" plus the PhotonNetwork.LocalPlayer.ActorNumber for the holder and assigns it as a parent, but it's still assigning both avatars to player 1 at the moment.
Hello.
everybody!
I am learning AWS now. We can use AWS services from Unity with packages directly.
But for instance, if a website? How do they use this? Do they need to use API Gateway? Or Can they import the SDK exactly like us?
I don't really know multiplayer too well, but just looking for a general idea for now: what would be the best way to be able to see the screens of multiple mobile VR headsets on a PC? Having either a few onscreen at once in a split-screen view, or just being able to cycle through them one at a time. Would something like sending one eye's camera view to a rendertexture and sending that to a host computer work? Or would there have to be a full multiplayer implementation for it to work smoothly?
You don't need to send visuals, that's very costly. Instead you can just sync everything else. I only really know Photon, but if you use photon you can just add Photon Transform View components to every object and position and rotation and scale will be synced without any extra work. And if you're saying you want to view from the other player's headsets, you can just access their camera directly.
Thanks. Would be local/wifi only, so something like Photon Bolt would work? I just wasn't sure how much things would have to be built from the ground up for networking, though. So essentially, it's just a script you attach to any object that moves and it'll sync automatically?
Photon Pun. Yeah, and there's an animator component that syncs up the animations as well, it's all very streamlined with Photon, albeit, there are some annoyances lol.
https://www.youtube.com/watch?v=p8YQpcoaPoU&list=PLkx8oFug638oMagBH2qj1fXOkvBr6nhzt&index=2 This is a good tutorial series on it
Become any tier member on my Patreon below for the source files!
Would you like to help me grow? There are a variety of ways you can support me here: http://firstgeargames.com/donate/
Depends on how the website is set up?
What specifically in AWS
Because afaik thats a very broad term
dynamo, storage
cognito
user will get authentication, reach the dynamodb tables and find the proper location of the Assets, and will download these assets from storage @icy thorn
Are you using some framework for your website?
Oh ok
one collague is responsible for react.
no, just we are trying to find a good practice. if we use SDK, then we will implement our backends
there will be different backends. but making it with API level-code, make sense but much work.
I could not decide...
@icy thorn
Thanks
Would something like that help?
Are you using network transform?
It looks like you may not be sending other clients the animation triggers. If the animation triggers are not being sent to the other clients the other clients won't know that they are supposed to be running them. I have seen that give jumpy animations like that in the past.
i have network object, network transform, and network animations components on it.
and all the animation parameters are checked
So I've been stuck on this for a few days now: This wheel script that I'm using absolutely does not like to be reconciliated
if anyone has any guesses as to why, please ping me. I've been on this problem for days and I'm getting nowhere
The physics go all wonky and get completely fucked when I have reconciliation on using this script, and the car refuses to turn at all
You should isolate between animator and network transform issues as this could be either.
I would 1. Disable network transform (breaking movement temporarily) and see if animation issues continue.
1a. if they do continue then debug your animation triggers and make sure the clients are getting the triggers by running the client in the unity IDE so you can see the debug for them.
1b. if the issues go away it is the network transform settings vs movement code.
Feel free to DM if desired.
Does anyone know if there is a simple P2P networking solution for the 2021.1+ build of Unity? I need to use it for their fix to the "Pixel Perfect Camera (Experimental)" for URP. But, I'm hesitant to use a non-LTS version of Unity for a complex game project -- AFAIK Mirror (what I was going to learn today) is only compatible with 2019/2020 LTS.
I don't really know where to begin with MLAPI or if it's compatible with non-LTS. If it is, are there other big risks with going non-LTS?
Mirror recommends the LTS versions of Unity. It does work in 2021.x unless Unity breaks something
Oh so, theoretically if theres nothing wrong with, say, 2021.1.15 - then I have nothing to worry about
In terms of Mirror specifically
P2P is a whole other issue, since Mirror is server-client model. Even if a player is acting as server/host, they'll need to port-forward / set firewall or you'll need a public relay
So if Mirror uses client-server its not actually P2P then?
Right. Jump over to Mirror's discord and we can discuss further - I don't spend much time in this one (one support venue is plenty 🙂 )
Let me find it, thanks!
asset store has the link
im doing some networking so does anyone know how to get the ipv4 adress using c#
i found it lol
using //unity stuff
using System.Net;
//code
void Start(){
string hostName = Dns.GetHostName();
string ip = Dns.GetHostByName(hostName).AddressList[0].ToString();
}
Hello! I've recently updated my photon project to 2020.3.14f1 and now I cant press anything because of this error: Operation LeaveLobby (228) not called because client is not connected or not ready yet, client state: ConnectedToMasterServer
No clue what happened at all
It worked perfectly fine before the upgrade
@limpid sky What do you mean by press anything? UI elements?
Also the quit one
EventSystem provides a detailed debug info in the inspector if you aren't using the new input system
Could see if UI is detecting anything
fixed the problem, thank you!
I have problem with porting my moving platforms from singleplayer to multiplayer. All movement for players is working great but when player stands on rotating platform nothing happens and I don't know how to handle it. In SP I had code like this cs private void OnTriggerStay(Collider other) { other.transform.RotateAround(transform.position, Vector3.up, 5 * speed * Time.deltaTime); } how can I get it to work on multiplayer
(PUN)
okey I discovered I cant change players position via transform.position = new Vector
I need help with the PUN instantiate function with custom data.. I used it to send only 1 data before... now i want to know how to use it to send more than one... and that's without using OnPhotonInstantiate cause I have a class I inherited from before... any help?
Hello.
What approach would be better,through API or SDK, if my application won't share its backend with any other applications?
I have two options, either using AWS LAMBDA and API GATEWAY, or just DYNAMODB package for unity.
I really need to be guided. thank you
Sdk is the way to go if you aren't just hitting exposed api GW endpoints with http requests
[Unity MLAPI] does anybody know how to get a component from instantiated network object? This only works on a server.
[ServerRpc]
private void SpawnGrenadeServerRpc()
{
// Instantiate grenade network object
NetworkObject grenade = Instantiate(Grenade, mortarBarrel.position, Quaternion.identity);
// Set ownership to player for game statistics
grenade.SpawnWithOwnership(OwnerClientId);
// Launch grenade
grenade.GetComponent<Grenade>().launchGrenade(mortarBarrel.forward * grenadeLaunchSpeed);
}
hello, i have an issue with mlapi, i am using a host and join button in scene 1 and the playground in scene 2, however i cannot see player 1 when i join the playground but when player 2 joins i can see him. but player 2 cant see himself
like this
I don't know why I can't call that method from Grenade script, because when I debug who is the owner of that component, It correctly logs client's id. So I can access the component, but can't call method from it..
After I call .launchGrenade() method from ServerRpc, this method correctly logs given velocity as well as owner's client id, yet .AddForce() is triggered only when host si using this ServerRpc, in the case of a client function only correctly logs velocity and id, but .AddForce() is not triggered.. I don't understand.
SCRIPT N.1
[ServerRpc]
private void SpawnGrenadeServerRpc()
{
// Instantiate grenade network object
NetworkObject grenade = Instantiate(Grenade, mortarBarrel.position, Quaternion.identity);
// Set ownership to player for game statistics
grenade.SpawnWithOwnership(OwnerClientId);
// Launch grenade
grenade.GetComponent<Grenade>().launchGrenade(mortarBarrel.forward * grenadeLaunchSpeed);
}
SCRIPT N.2
public void launchGrenade(Vector3 force)
{
Debug.Log(force);
Debug.Log(gameObject.GetComponent<NetworkObject>().OwnerClientId);
RB.AddForce(force);
}
Hello, so I can make a database using SQLite by following this guide: https://medium.com/@rizasif92/sqlite-and-unity-how-to-do-it-right-31991712190
My question is how would I put this database online? I get that databases can hold the data for me and I can read from them, but how can I save this database somewhere so my app can read from it and that everyone who is using my app will have the same data? Or maybe I'm not understanding how to properly use a database for a unity game. Anyone have any tutorial links they can send my way?
I'm pretty stuck on setting up my network project. Is there anyone that can PM me, and help me hash my problem out? I've been banging my head for months/going through tutorials that are not exactly helping my problem. I don't think what I'm doing is very complicated, just a bit heavy with deeper concepts that I need verification and another push in the right direction...
Why is no one responding in here
There's an MLAPI specific Discord (see pinned messages in this channel). You might find more people who can help you out there. Regarding your issue, I'd need some more information to be able to help, how are you spawning the players?
Hi, I know. But what I am not sure is which way should I go?
I followed one of the latest tutorial from dapperdino and changed under the if statement instead of turning on some UI changing to the next scene
Can you describe what you’re trying to do? 9/10 times I’d say http + api gw is the way to go. There are security concerns to including the sdk and credentials in your client app directly.
That’s a guide on how to run a local db. It sounds like your goal is to have some shared online database, like a high scores table. For that you’re going to want to host a database online using some service like mongodb, heroku or fire base or http://dreamlo.com/ then make HTTP requests to add or delete or read items from it.
Super simple to implement leaderboards and user management for your games. Works on lots of platforms. No signup required.
So i never touched networking before and i was wondering, what it's the easiest solution i can learn? (MLAPI or old ones?)
Thank you! I'll look into this
How can I live stream recorded audioclip data from the microphone to my server? I've looked into doing chunked transfer, but UnityWebRequests doesn't seem to support me modifying it after it was sent. Originally I was thinking I could potentially attach a stream of some kind, but now I'm not so sure.
Is there a way to do it with rest? Should I look into sockets or grpc instead?
You cant/shouldn't stream AV over http to a "webserver" (depending on what you mean by that... guessing since you mention UnityWebRequest). There is always System.Net.Sockets... https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets?view=net-5.0 Other than that... SaaS with SDKs, or some library might exist depending on your needs. As an alternative to UnityWebRequest you can use System.Net.Http https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=netstandard-2.0, which gives you full control
Part of what appealed so nicely to me is that I can handle incoming request streams super nicely on my node server using busboy parsing of the multi-part form data:
app.post("/conversation", (req, res) => {
let busboy = new Busboy({ headers: req.headers });
let transcription;
busboy.on("file", async (fieldname, file, filename, encoding, mimetype) => {
if (fieldname == "audio") {
transcription = await transcribe(file);
~~ other stuff, eventually returns a audio buffer ~~
}
});
return req.pipe(busboy);
});```
which allows me to work directly with streams (file is a stream in this case) and to transcribe the audio content I'm receiving more quickly. I was hoping there was a way I could extend that concept even further by having the POST request sent out early, and appending the microphone input bytes as I receive them
thats a different kind of stream than what you might want to use for AV streaming
greater context of what I'm working on:
Working on a side project to use GPT3 in video games for non-player characters:
my flow essentially is
1.) record voice
2.) stream voice to google speech-to-text
3.) take text result, add to gpt3 prompt, and send to gpt3
4.) take gpt3 response, and send to google text-to-speech api
5.) play audio result back to user
trying to turn the beginning of that flow into
Stream microphone input from unity -> Backend Node Server -> Google Transcription API
you're just uploading files then, thats not "streaming"
I'm not sure I understand the difference
It processes the data as it receives it, not after it's compiled it together
the difference is in how big the chunks are and how live/responsive the service should be
to my understanding the tcp/ip connection made between the client and the server can be modified after it's sent, unitywebrequest doesn't support it though
my idea was to stream the microphone data into this request, which my server is equipped to process as it goes
will look into this though: https://docs.microsoft.com/en-us/dotnet/api/system.net.httpwebrequest.begingetrequeststream?view=net-5.0
That's not what tcp/ip is good at, but in a prototype it might work.
those streams really are meant for reporting on transfer progress of larger messages
also the compute-performance-requirements of that flow are gonna be extreme
Didn't realize this but all the methods I thought I could use of carrying this out, http, sockets, or grpc, are all based on tcp
sockets (as a concept) aren't bound to any particular protocol. Only an instance is.
oh gotcha
been meaning to do this for a while now, but if I've kinda hit a dead-end with my http/rest implemention, kind of thinking of implementing this with gRPC
https://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data
found this stack overflow, in it they use GetRequestStream() which opens a connection to the server. Couldn't I mimic it but then stream microphone data into the request as I get it?
hello everyone I am trying to figure out how to set a gameobject active using photon in unity but I cannot figure it out I have looked it up and cant find anything, does anyone know how to do it?
Does anyone have experience with photon voice and audio sources, I seem to be having a problem with something called audio frames and it's stopping my voice chat from working
This is the error im getting
Why are you trying to impose additional latency and overhead? As Anikki says, sockets arent protocol specific. If you want to do something custom, with specific latency and bandwidth requirements (which i assume the audio streaming is), then your best bet is to try to hand roll an implementation.
UDP has better latency, but you would have to packetise the stream into chunks. Also, its unreliable, so you might miss packets and have to resend them.
TCP is stream based, so you coukd send a continuous stream of data. It can suffer from latency issues, but when just trying to upliad an audio stream this isnt an issue
You should take a look at the System.Net Sockets. The Send and SendTo methods are what you want.
Not trying to impose additional latency or overhead, I wasn't sure the best way to approach it. I've worked with TCP sockets before, but not UDP and based on my quick googling was slightly scared off and was learning in favor of trying gRPC, which is supposedly really good for duplex streaming
Goal is to have as minimum latency and overhead as possible, and if UDP is the best way to do it then I'll look into it
How long is your audio processing going to take? How largr are the audio chunks you are sending
It could be possible that you dont have to care. That a simple upload will br enough
You might be able to get away with sending the audio, listening for the text, sending the text, and listening for the response, all over tcp
You say your voice is being sent
Would players voices be sent?
Or is this just a side project, and not a game prototype?
Do google provide anything other than REST endpoints for their services? Same question fkr gpt3? Or are you going to be running a local inetance of it?
(I forget if they made gpt3 public or not)
Haven't profiled it. Player uploads complete .wav file to server, that audio's file stream gets sent to google's speech-to-text via their gRPC api, text is received back and sent to GPT3, and then the text result is sent to google's speech-to-text api, before sending the audio buffer back to the payer.
You're right in that I might be barking up the wrong tree though. I already have a working implementation using normal POST https://www.youtube.com/watch?v=QrmjSw7rCA8, and the time savings from switching to a fully streaming setup might be minimal compared to the actual compute time of gpt3 and more specifically the voice synethizer. Might be best to keep working solution and focus on speed optimization later.
Yeah, "premature optimisation id the root of all evil", etc
That looks reaply cool so far! Gj
Starting to feel the pain of that. Spent the day experimenting with different approaches to speed it up to try and get it to as real time as possible, but I'm starting to think, just anecdotally, that the biggest time spent is on the text-to-speech api. Might spend tomorrow profiling all of this, rather than trying to perfectly optimize everything
But yeah the lag in between you talking and the npc responding is probably due in large part to gpt3
Also speech to text
Profiling is very important
Watching the server logs, the response is pretty quick, so it might not be text-to-speech or gpt3
How does the node server work?
Thank you for your held kirb!
I get authenticated by HostedUI via OAuth2.0 and replace the code by tokens. And in the application I am going to use, DynamoDB, Storage for the first phase.
There will be Unity application, and two React application will use the same backend.
But I insisted my friend to use SDK instead of using HTTP and lambda things since it is easy to implement and wont share our backend to anybody.
And why do you think it is unsafe to use SDK? We do not put any code in it but the id pool id and the hostedUI link.
Hi, I have an api (created with python/flask) and this sets a session when the user logs in, in a normal browser this works and the session is respected across different api routes. Does unity have something similar that keeps the session like a browser does?
Hello.
In DynamoDB, can I make restaurant table as "restaurant city = partition key" and " restaurant name = sort key"
Does it make sense? Or what shuld I do
public async Task<Token> GetTokenForNextTime(string refreshCode)
{
Debug.Log("refresh key ile token alınacak.");
string text;
do {
Debug.Log(refreshCode);
var request = new HTTPRequest(new Uri(GeneralConsts.USER_POOL_DOMAIN), HTTPMethods.Post);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddField("client_id", GeneralConsts.CLIENT_ID);
request.AddField("grant_type", "refresh_token");
request.AddField("refresh_token", refreshCode);
request.Send();
text = await request.GetAsStringAsync();
Debug.Log("refresh key ile token ALINDI.");
} while (text == null);
return JsonConvert.DeserializeObject<Token>(text);
}```
Hello this gives me throwfornonsuccess. do you see anything unusual?
AWS cognito
there is any way to remove code from the client build but keep it in the server build? like database things
I think it is not secure to let it stay in the client considering decompilation
anyone have a clue? it's also hard to have separated projects, considering most of things gotta be synced to make the game work
the client could connect to an API to send/request data? yes but it gonna be more slowly for sure
I think this approach is the corret one tho
maybe I'll make a ZMQ server to handle the database
anyone have a suggestions?
but will this code be 100% deleted from the client build? or it is just no run? I read the docs but still not 100% sure tho
and thanks for the reply
In C# you can use a CONDITIONAL attribute which is a more clean, less error-prone way of stripping out functions
looks like it delete
it will be completely removed
you can confirm by using something like DNSpy on your built assembly
hmm thanks a lot for the help
gonna use this method for sure
why is networking so undocumented? how do people do this?? i just wanna use steam servers but i literally cant find anything regarding it
im trying to use photon but its not telling me anything regarding using steam servers, they want me to use their servers and pay i guess?
the ones i do find seem to be direct player to player connections, which isn't what i want
can i use photon voice with mirror?
You cannot use steam servers with your own games.
You can use Steamworks (Steamworks.Net / Facepunch) to use steam networking for p2p connections via the steam relay.
You can probably use Photon Voice with any networking solution but not sure about that one.
wait wdym, when steam servers go down games made with unity also go down (scp secret lab for example)
and that game uses mirror
is that what steam relay is?
when players connect over steam?
SCP just uses the steam relay afaik.
oh alright
i just want players to be able to play without having to port forward, like a phasmophobia style menu/lobby
With Photon 2, I'm using a Photon Transform View for a cube being transferred across players in VR, but for some reason the cube will constantly shake and be a little delayed
Is there a better way to send the position of the cube across the network that will be more accurate?
does the cube have any rigidbody or anything on it?
Yup!
that is probably why
Should I have it be kinematic while it's grabbed?
yeah i would
Alright I'll try that out
is there a preference for the movement type? Right now I have it on instantaneous
idk ive never used pun successfully
xD
that was just my guess for the reason
right now I have room listing and other stuff going on, so it's just the interactions that are giving me trouble lol
I'll let you know how it goes
im trying to figure out how to make a server list in mirror rn
ive never done networking right
and i just took on a super ambitious project
I followed the VR tutorial, since I'm doing it in VR, but it seems like the process is basically the same for non vr
eventually I'll have to make this PC compatible
im working with vr for the first time
so then non vr users can run it
bruh mine is gonna be vr and pc cross platform
pog
networking is new to me too
well for photon, it updates on the RoomListUpdate
so everytime a room updates
it'll store the List of Rooms to a script, and then store that info in another list
and then I just go through the list and instantiate a ui for each room
accessing the info in each one
o
i cant even figure out how to like
get open rooms
and if i do figure it out i wont have any way to test
cuz im using steamworks.net
and dont have any friends that would help me test
yeah I have to like use my quest
and then hit play in unity and look at the scene view
this is what manages the room list for me
and then RoomListing is a class I made that sets the info
I made this following a tutorial, but it's getting called in this event
OnRoomListUpdate will happen everytime rooms update
So if someone makes a new room, this is automatically called
or if a room closes, etc
originally I was going to use Mirror because I bought a Udemy course on it, but then I decided to use pun2 instead
i was the opposite
i started with pun2 but couldnt find anything at all about steam support
like joining via steam and stuff
so i just gave up and switched to mirror
dapper dino had a pretty good tutorial on it
but he didnt go over making a room list afaik
So for pun2 and steam, don't they have their own SDKs?
So basically you'd just use the list from the Steam SDK and their own stuff for things like friends list etc
but then for the multiplayer part you would just have the players connect to the servers using pun2
I'm not really sure, I didn't even know steam had an sdk until I googled it a sec ago lol
this guy maybe solved the issue?
o i dont mean steamvr
i mean like
steam relay connections
and steam authentication and stuff
but
i just switched to mirror and ive made some progress
im just making a simple main menu rn
what project are you working on?
its a game about storm chasing
lemme compress a vid i took for my friends a couple minutes ago
thats my menu rn
im gonna put a world canvas on that monitor for the actual ui
@cunning sluice if you decide to use the steamworks api i figured it out
painfully
protected Callback<LobbyMatchList_t> lobbyListRequested;
private const string HostAddressKey = "HostAddress";
void Start()
{
lobbyListRequested = Callback<LobbyMatchList_t>.Create(onLobbyList);
SteamMatchmaking.RequestLobbyList();
}
private void onLobbyList(LobbyMatchList_t callback) {
int lobbiesMatching = unchecked((int)callback.m_nLobbiesMatching);
List<CSteamID> ids = new List<CSteamID>();
for(int i = 1; i <= lobbiesMatching; i++) {
ids.Add(SteamMatchmaking.GetLobbyByIndex(i));
Debug.LogWarning(SteamMatchmaking.GetLobbyData(SteamMatchmaking.GetLobbyByIndex(i), HostAddressKey));
}
}```
You should use Fusion, client predict and snapshot mode
Global cross platform multiplayer game backend as a service (SaaS, Cloud) for synchronous and asynchronous games and applications. SDKs are available for android, iOS, .NET., Mac OS, Unity 3D, Windows, Unreal Engine, HTML5 and others.
for a multiplayer card game service, could someone recommend what to use for the networking aspect
how do i make a player to player connection? rn i only have it player1 to server to player2, which is slow (using udp )
This site provides Unity Multiplayer documentation, references, and sample code tutorials.
Mirror and Photon are two other great soultions for Unity @gilded jay
I recommend researching "peer to peer networking unity". There are networking stacks in Unity that supports it, such as Photon Bolt and Mirror LRM
i decided to try and use udp hole punching method
Personally I strongly recommend MLAPI over Mirror, not least because it's now officially supported by Unity. It's also easier to use and more reliable because it doesn't rely on a complex code weaver
In Photon2 I'm having an issue where the cube being passed from player to player in VR is laggy, any fixes?
Currently using Photon Transform View, I've tried parenting it to the controllers, and turning in kinematic when it's picked up and so far it hasn't helped
if anyone would like to stomp on me feel free to, i just spent 3 hours debugging why i couldnt see my lobby when it was just set to private
What is the best package for developing multiplayer games in unity? I have a sound knowledge about programming and backend development but not about unity. Please suggest 🙂
I had just assumed pun 2 = photon 2 lol
yes pun 2
I thought it stood for photon unity network 2 or something
I'm probably wrong haha
Hello. this question is regarding AWS dynamoDB
I have a restaurant app my question is
My primary key consists of "RESTAURANT CITY" as "PARTITION KEY" and "RESTAURANT NAME" as sort key
is this good practice?
2.Question. I have a JWT ID TOKEN. But how can I decode it? Which library?
lol, I have done that before.
not mirror
source: am using mirror
what’s wrong with it?
Am using pun2
Does public override void OnRoomListUpdate(List<RoomInfo> roomList)
Not work anymore?
I am using Photon.Pun
And the behaiour is MonoBehaviourPunCallbacks
And if not pls tell me the right syntax
its stupid
cant have children objects networkef
ExitGames provides several high end solutions, like Photon Fusion and Photon Quantum, but if you just want something that can do the packet sending, there are bunch of transports to choose from. A lot of solid transports are implemented in higher level networking solutions like Mirror.
The last unity net demo used photon realtime for transport, which is what all photon products use for backend transport more or less
Need help pls
No it doesn't work like that anymore
I actually have an asset soon to be release to handle this
However there are still ways (aka see astroids demo or pun cockpit)
public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
foreach(Transform trans in roomListContent)
{
Destroy(trans.gameObject);
}
for(int i = 0; i < roomList.Count; i++)
{
if(roomList[i].RemovedFromList)
continue;
Instantiate(roomListItemPrefab, roomListContent).GetComponent<RoomListItem>().SetUp(roomList[i]);
}
}
Thank you
It works, I'm using it currently to list rooms
Huh...
Did you make sure that players join a lobby first?
It'll only update on their client if they're in a lobby
Yea i did
Though
Theres an error
Ur missing thing one
That means its not a part of Photon.Pun
I wanna make in my fps project "dying mechanic", but I don't know if I should destroy players prefab or just reset values and teleport to spawn point. Which is good way to handle something like that?
Ye bruh it actually works u just need to include using Photon.Realtime
@river meteor The question is pretty similar to should I pool or not. Pooling is a neat way to get rid of the Destroy and Instantiate cycle, but does require implementing some sort of reset to all component state. Whether you think it's worth it is up to you.
I don't think the networking side cares too much assuming you don't have some large initial syncs for whatever reason, since the streamed data probably overshadows those relatively rare events.
slap a coroutine on it then when it acutally destroys just do PhotonNetwork.Destroy(gameObject);
bruh i posted a method not a clas lol, but yes, likely may require realtime import. BIG NOTE FOR PEOPLE USING PHOTON: DONT NAME YOUR GOD DAMN PLAYER CLASS 'PLAYER' LITERALLY ANYTHING ELSE IS GREAT JUST NOT PLAYER (this had me bent over like a prison pinata for like 6 months figuring out why my game would like, only work depending on the phases of the moon (aka c sharp just like, casting shit one way or the other)
I mean, it likely would have whined about ambiguity between your Player class and theirs, you could just fully qualify it like Photon.Realtime.Player myPlayer ...
Not sure of the exact namespace for theirs
yea, same here!!!!!!!
but it didn't
it is evil
Is your IDE configured?
of course, in fact both rider and vs i used, in fact, i even used rider in linux
its not htat
its that
you can import photon.pun
which doesn't include photon.realtime.player
but photon.pun.rpc for example can take a parameter of type player
in fact, a lot of photon.pun namespace stuff uses photon.realtime.player
so its just goes to c sharp JIT hell i guess
but considering the solution (right click -> refactor/rename -> Player -> PlayerScript) i'd say risk to reward, especially considering i'm not the only one who had this issue, is prolly worth it
also, if player class inheretes monobehaviorpun, it now has photonView, which has photonView.Owner, which is type Photon.Realtime.Player, yet you only import photon.pun
I'm trying to create a steam network thing with mirror i have an issue that when i load my lobby scene from my menu scene the network manager just... dissapears? (in the lobby scene) I have checked all of my DontDestroyOnLoad objects and none of them have a duplicate NetworkManager because i know that duplicates cause errors, nothing sticks out in console either.
whats your like, transport layer or am i dum and steam does this now?
FizzySteamworks
oh huh never heard of thta i gotta look it up
lmao
so its pure p2p, and you gotta port forward and all that
thats the one nice part of say, photon realtime for transport, since it uses a relay, IPs are masked and it has like, trusted in all but secure business environment punchthrough
plus you can implement your own relay and put minimal (or maximal) logic on it
yea i dont know anything on this i cant help you i can only suggest other stuff that doesn't help you at all lol
no, i didn't think since i was using that namespace it was causing any issues but eventually i said f it and magically, intermittent errors went away, then i started participating in the photon forums/discord more and at least 2 other people had weired issues, i suggested that, and they said it fixed it
the ide/assembler should get mad at you, and so should unity, but it didn't
Hey, I'm looking to learn Unity development over the next few years and I've done several basic tutorials, I roughly know my way around the editor, and I've done .Net development for years, so Unity is taking a hobby to the next level.
That said, I'm looking to create a base Multiplayer First-Person-Viewpoint framework using MLAPI to support 64 player connections to a server. The problem I have is that when I connect more than one client, the camera shifts. I've separated the prefab entities so each client's input moves only their entity, but ownership of that entity and the camera still reside with the server.
My question here is simply;
- Why does MLAPI do this by standard? What scenario would require new players to join and overwrite existing viewpoints? And, on that topic, how do I stop the default spawn prefab process via Network Object so that I can do it myself properly?
Anyone?
Are you deactivating the cameras on all the player objects of which the client is not the owner of?
Ownership of a player object does not reside with the server with MLAPI but with the owner client.
That’s exactly my issue, the server is the owner. Even when I spawn multiple clients, all of them state ownership is the server, and surely that shouldn’t be happening, right?
What do you mean by spawning multiple clients.
I create multiple client windows from the build and one server.
Input to move the objects is fine.
Cameras just don’t work
Can you share your code for input and cameras?
Give me 5, I’ll need to reopen the project.
@verbal lodge so this is what handles the command line input to generate the server and 3 clients:
https://paste.ofcode.org/shVdccLavRWPpDmHpykNxe
I run the executable with -server switch, and then 3 more without it.
Yeah that code looks fine. I'd need the one on your player object
Then this is my very basic game manager doing nothing really except providing a gui for the server to show its the server, and then the bit at the bottom is my frustration trying to find a way to get it working:
https://paste.ofcode.org/5K29NSLw3cFmfNL8rZfKG2
This is the player movement:
https://paste.ofcode.org/VjzTkK6NhugEtbynafiVzH
and this is the camera enable:
https://paste.ofcode.org/ZYdh47xkTmYB6Bx3LayvhY
That should give you an exception. A client cannot spawn a network object
Only the server can
So SetupClient isn't really doing anything here right. Your player object is just the default player object which MLAPI spawns.
The bit at the bottom marks as setup complete when the server runs it anyway, it doesn't actually do anything. I basically tried just about anything I can think of to get the camera to work... i.e. prefab the camera, marking every object under the prefab as a network object, and then not, having an empty as the prefab which contains the rest, and not
Correct... but MLAPI spawns it with server ownership
not client ownership
So for the camera replace Start with override NetworkStart and it will work. This is a UX issue which we have in MLAPI. Ownership is not defined yet in Awake/Start
As far as I'm aware only parent object should have NetworkObject component
Unfortunately it hasn't changed the camera issue, but strangely I am now seeing the ownership field update for the client connection to "2" for the second client on the prefab item.
This looks correct, right?
Don't know If I can be of any help, but I have 1 player prefab that has Camera as child and a script attached to it, inside of that script in Start function I just do this:
void Start()
{
if (!IsOwner) return;
PlayerCamera.SetActive(true);
spawnCharacter(Vector3.zero);
}
And everything works fine with me, what is strange after reading this conversation between you two 😄
@plush flint If you spawn multiple clients to connect to the server though, do the cameras remain independent of one another?
Yes everything works fine, just tested it with multiple clients
and where have you attached that script above, and what type is it? MonoBehaviour / NetworkBehaviour?
NetworkBehaviour, its basically just a prefab that has camera as a child
lol exactly the same setup I have
so the parent is the one with the script
yet every new camera that gets created in my framework, it jumps the servers and the clients to the newly created camera, even when the camera still shows as disabled in the heirarchy when its spawned
You really should not use Start
There is no guarantee that it works. Use NetworkStart for network behaviours
Oh okey, thanks a lot
I'm so lost with this. I just can't understand where this is going wrong. The tutorials really aren't very helpful in setting up a multiplayer game when this is a fundamental issue right out of the blocks 😦
This is basically my editor window with host and 1 client, clients camera is disabled, you have it the same way? I use ParrelSync so I can have 2 editors open for easy debugging.
Maybe I'm just wrong... do you disable the component by unticking it in the explorer?
This bit, right?
Clicking that checkbox will disable/enable the component
I'm disabling the whole camera gameobject but that should be of any difference
Maybe that's where I'm going wrong.
btw I'm very new to all networking stuff and ParrelSync package helps so much with allowing me having 2 editors open and seeing whats exactly going on there, its also faster than always creating builds. So maybe you could try it if you want it should help a bunch
You could just manually disabling camera components on clients editor and see whats going on there
Nah, still doesn't work disabling the entire camera gameobject
just to be sure, the networkobject prefab that you are spawning, it initially has camera gameobject disabled right?
and you only enable it when it's the owner
See this is what's so confusing... take a look at this, this is the second client to join in to the server:
Here's the prefab, the camera is DISABLED!
Yet, its the active view for that client, the other client, AND the server.
yep, this is the full prefab:
The first picture where it says isOwner: false, it also says isOwnedByServer: false so who owns that gameobject? 😄
this is what's entirely baffling to me lol... all I'm doing is specifying the game to run from the build via command line, without any arguments.
OwnerID 3 is the correct ID too... its the 2nd player to join
If my calculations are right, the second player should have ownerID 3
yeah, so that's really confusing 😄
From editor you connect as a client, and from one of the builds as host right?
Aye, the build hosts it, then I connect from the editor, then connect from the build
I've spent 14 hours looking at this now, and it's insanely frustrating that it just doesn't do what it's supposed to do 😐
Well at that point, I would probably open DapperDino's channel, view video where he is spawning players, copy the whole thing, check if it works and if yes, implement it into my project, if not I would probably start crying
Doesn't MLAPI have samples available?
Yeah, but they're not particularly helpful. The FPSSample took forever to download, install etc... but I can't even find the start or the network manager that all of the tutorials use
You mean this FPSSample? https://github.com/Unity-Technologies/FPSSample
Yes
That's not MLAPI
Explains why I couldn't find any references to it... It's linked on the MLAPI page though as a showcase for MLAPI
You mean this page? https://docs-multiplayer.unity3d.com/
IDK, I can't remember where I found it. Either way, it wasn't too helpful to understand it, and all of the tutorials on that one you just linked haven't helped, they've essentially got me into this situation where cameras are never unique, and instantiating doesn't work correctly. The only thing I've changed really is the prefab that's used, and the inputmanager with a keyhandler to accept wasd inputs
FPSSample does use Unity's transport layer, which is basically the lower level component for the higher level part, like MLAPI and Mirror, which implement several transport layers.
Most packages have samples listed for it in the package manager
I'm not seeing any:
Might have something to do with being a git package
Still not on the package manager natively? 🤨
nope, not on the current 2021.1 release either. I'm on 2020.3 though
Oh MLAPI is still v 0.1.0? The heck y'all doing? Pick a networking framework that at least thinks it's ready for use 😄
Other networking frameworks have limitations with hosting, usage, or concurrent player counts
I think I did check mirror out, isn't that the one that cannot be used for cloud gaming?
What do you mean by that?
something I read somewhere that with certain multiplayer networkings you can't use your solution for cloud-gaming without breaching Unity's ToS... which is why I was looking at MLAPI because its owned by Unity
Oh the SpatialOS thing
Ah yeah, that's the one... they used mirror network framework right?
It doesn't affect developers running their own servers for their own game.
(I'm not a lawyer, this isn't legal advice 😄 )
SpatialOS is their own thing that provides hosting for other games. There was a licensing dispute there
Aye, but they also had a multiplayer FPS framework which used mirror for networking
and then a few short days afterwards, the whole dispute kicked off
Kinda doubt they were using Mirror
I'll give it a shot and see if I can get at least a step further ahead than with MLAPI anyway
You can also see bunch of other names here https://forum.unity.com/threads/what-are-the-pros-and-cons-of-available-network-solutions-assets.609088/.
The "Spatial OS thing" had nothing to do with Mirror. If you are creating a game with Unity, you can use cloud hosting solutions to host a Unity server without breaking ToS.
I have a problem with Photon: when a second player enter the game, I have a second player 1 instantiated too
and a second problem, when I try to connect to Photon with the game build and the unity Game test, players don't seems to be in the same room
Make sure both clients ended up on the same region
You don't have the player object in the scene by any chance? Possibly duplicate player spawning logic?
thanks for answer, no player in the scene, just instantiate
@spring crane Mirror did in about 15 minutes what MLAPI took me 15 hours of troubleshooting couldn't fix.. thanks 👍
I know you can find lot of tutorials with PUN 2
anyone in here ever made a game using server authority mode?
where you have a master server that spawn new rooms for the players?
Depends on usage. Pun looks like it has server requirements to be on their platform and CCU caps.
Mirror is self-hosted that you can stick on any hardware / cloud it.
How does server / client tick rate work?
Do you need to sync the current tick for the client and server?
Hey, i want to make a Multiplayer game which only contains UI which send data between the Players. Is Mirror good for this or did you know a better Solution.
where should i start learning networking with mirror
DapperDino and First Gear Games have some useful tutorials on Mirror on YouTube
I'm not sure if this is a "general" coding question, or a "networking" question... but from a performance perspective, is it better working with classes attached to GameObjects that can then be synced to the server, or using network variables?
Hey guys! I was wondering if there are any good TCP/UDP client and server solutions. I want the client and the server in a different project. I've seen some attempts on this problem, but ive only stumbled upon on barely OOP code with insane ammount of public fields with no getters and setters. Thanks in advance.
❤️ this looks something i was looking for
how can this translate this into url in unity? doing this id = 4 doesnt seem to work
HI, gyus! Question about PUN. I have a problem with destroying go. I have gloves prefab that contains 2 child: leftglove and right glove. Gloves prefab is set to mainGloveContainer and left and right to theirs containers accordingly, so there are 3 containers total. When i try to PhotonNetwork.Destroy left and right glove i have an error on other client:
It seems that photon tries to destroy main glove go as its id is 1008. But it has been already destroyed
I would really double check what is being destroyed, since PN.Destroy doesn't seem to be travelling to parent objects looking for a PhotonView and viewid mismatch seems unlikely.
i solved the problem by setting gloves part's parent back (sending RPC) to Gloves prefab (in gloveMainContainer) prior destroying. That is probably spare rpc but the only solution i found
thanks
Hi, i have a question. In TCPclients, Byte[] bytes = new Byte[4096]; <-- specifically, this line... what does that do exactly? I have a large (variable size) of a packet that comes in from the server as a json object. Is that byte size limiting me from getting the whole json object?
or does that simply split the packets in 4096 byte chunks and they get reconstructed by the client?
there is limitations for PhotonViews components and RPC calls? (PUN)
That means you can only receive 4k bytes at a time
So either theres chunking
Or it can only deal with fixed size packets
so can i guess my next question would be, how can i not set it and let it figure out on its own?
If you have a variable size packet, you need to allocate a fixed size buffer for the header (which must have the length of tbe data segment) and thrn you can collect the whole packet
If you dont want a header, you should store every chunk, and append to a single list or somethin
Only stop appending and try to read the packet when an 'end-of-packet' is reached
What that specifically is depends on how you send packets
And you run into the issue that you will be blocking until the entire buffer is filled, which could contain 1 byte of the current packet, then 4095 bytes of a new packet
I would suggest going for the |size| . . . data . . . | approach, as its much easier
Are you doing networking yourself?
You cant, at least not in a clean, reliable way
You must know how much data to read, especially using tcp, because otherwise you risk blocking
and the channel history, it sends it at the beginning of joining a channel
and that's a big packet of variable size
You can set nonblocking, but that raises exceptions, which is slow
Are you willing to send custom, binary packets? Or do you only want to send json?
Are you willing to use sockets, or do you want to use TcpClient and friends
I would suggest going for TcpClient, and creating a custom packet structure. Send an int, with the packet size, then send all the bytes of your json string.
On the other end, read the size, then read that many bytes into an appropriate buffer
so what you could do is:
// receiving data
byte[] headerBuffer = new byte[4]; // buffer size = sizeof(int)
int headerBytesRead = conn.Receive(headerBuffer); // this is for a socket, ymmv
ReadOnlySpan<byte> headerSpan = headerBuffer
int bodyBytes = MemoryMarshal.Read<int>(headerSpan);
byte[] bodyBuffer = new byte[bodyBytes]; // this can be pooled to avoid allocation
int bodyBytesRead = conn.Receive(bodyBuffer); // again, this is for a socket
string payload = Encoding.UTF8.GetString(bodyBuffer); // the encoding can be whatever you want
// do something with the payload
// sending data
string payload = "..."; // get this somehow
byte[] bodyBuffer = Encoding.UTF8.GetBytes(payload); // encoding here must match previous encoding
int bodyBytes = bodyBuffer.Length;
byte[] headerBuffer = new byte[4]; // again, sizeof(int)
Span<byte> headerSpan = headerBuffer;
MemoryMarshal.Write(headerSpan, ref bodyBytes);
int headerBytesWritten = conn.Send(headerBuffer);
int bodyBytesWritten = conn.Send(bodyBuffer);
note that for both cases, you have to handle conn.Send() and conn.Read() returning a number less than the total bytes you need to handle
for that, you might want to use the following loop:
private bool TryRead(Socket conn, byte[] buffer) {
int read = 0, toRead = buffer.Length;
do {
int readNow = conn.Receive(buffer, read, toRead - read, SocketFlags.None);
if (readNow == 0) // error condition, connection closed on other end
return false;
read += readNow;
} while (read < toRead);
return true;
}
the TrySend version is very similar:
private bool TrySend(Socket conn, byte[] buffer) {
int written = 0, toWrite = buffer.Length;
do {
int writtenNow = conn.Send(buffer, written, toWrite - written, SocketFlags.None);
if (writtenNow == 0) // again, error
return false;
written += writtenNow;
} while (written < toWrite);
return true;
}
if you want to do your own networking, this is an ok starting point
but i would recommend you dont
when using TcpClient, a lot of this headache goes away
you would still have to setup some kind of packet structure, but you have to think less about errors
also, to handle channel history, just keep it on the client
append to a local file, with a history file per channel the user is in
have the option to delete the history file
that way your server is lighter, and uses less bandwidth
@quick cairn did i scare you off? :^)
lmao ermmmm.... no i'm trying to digest all of that HAHAHA
the only problem with that, is the the channel history will keep updating even when you're logged off
so at some point, when you login, you still need to fetch all the history
worst comes to worst, i'll get rid of channel history, in my case it's not really that important\
i was more concerned with the size of each message sent
about that 4096 bytes
thank you for your input i really appreciate it
I’m totally just going to bury my head in the sand and just hope the default networking stuff works 🤪
Hello,can somebody help me? I use mirror for networking. How i can fix problem when all players see from host camera? Now i make camera.depth = -10 and disable audio listener if not local player, but i think exists so smart ways ( i cant destroy camera if not local player because player selected item is child of camera)
Disable the camera if it's not the local player? Simple as it gets
if i disable camera player selected item will be disabled too
GameObject with camera and camera control script have a selected item in child ( if i move camera, selected item will be move too)
Yeah when I said disable the Camera, I meant the actual component called Camera
i need disable audio listener too, then i should disable camera and audio listener in every player class script, it breaks dont repeat yourself
Did you just ghost ping me?
Has anyone ever worked with UNet's Network Discovery's broadcast data? I'd like to use the broadcast data to transmit specific metadata using delimiters to clients searching for joinable servers, such as current server population.
However I realize that broadcast data needs to be set before hosting a server, and cannot be changed while the server is being hosted (I may be mistaken here). So this makes broadcast data useless for updating current server metadata to searching clients.
Is there a workaround for this, or perhaps I am mistaken? New to multiplayer with UNet/Mirror. Any help would be greatly appreciated. Thanks!
anyone know a good netorking totorial that would work for an openworld game (a dedicated server)
never use json for networking. Extremely slow.
Yeah, you dont say
Originally, i suggest using binary
But, if someone wants to get started using json its not an issue
And the question was about the packet structure, not the fastest way to transfer data
All it would take to convert a packet that uses json, to a packet that uses a custom binary structure, would be to add a new field to the packet header for the "packet type". Then have an enum for all of the different packets you send, and write the correct enun value into the packet header. Then write the individual fields of the packet, and read them in the same order
// you can use a different backing type if you have more or less types, to save a byte or two in the packet header. the default is int
enum PacketType : short{
MessagePacket,
HistoryPacket,
// add more types
}
// receiving data
byte[] headerBuffer = new byte[6]; // buffer size = sizeof(int) + sizeof(short)
int headerBytesRead = conn.Receive(headerBuffer); // this is for a socket, ymmv
ReadOnlySpan<byte> headerSpan = headerBuffer
int bodyBytes = MemoryMarshal.Read<int>(headerSpan.Slice(0, sizeof(int)));
PacketType packetType = (PacketType)MemoryMarshal.Read<short>(headerSpan.Slice(sizeof(int), sizeof(short)));
byte[] bodyBuffer = new byte[bodyBytes]; // this can be pooled to avoid allocation
int bodyBytesRead = conn.Receive(bodyBuffer); // again, this is for a socket
ReadOnlySpan<byte> bodySpan = bodyBuffer;
// do something with the packet
switch (packetType) {
case PacketType.MessagePacket:
// a message packet could look like |user id|utf8 message|
int userId = MemoryMarshal.Read<int>(bodySpan.Slice(0,sizeof(int)));
string userMessage = Encoding.UTF8.GetString(bodySpan.Slice(sizeof(int))); // get remaining bytes
// do something with tbe user id and message
break;
}
Sending packets is very similar, except that you write the header into the buffer, and you write fields into the body buffer at different offsets
Hello can someone help me make a sql multiplayer game the game is built just dont have the multiplayer fully working
Hello, I am very unexperienced with Photon/PUN/Networking and have been following a tutorial series by Welton King, everything has been working perfectly with photon until we made a room list function, players can see other players rooms, the names and players connected to the room but when joining the rooms players cant see eachother nor can they see any other functions that should be called through RPC's, any help?
Ive tried skipping the whole room list functionality and just making a join create button immidietly but that still doesnt work, something messed up when trying to make the room list thingy, if there arent any problems here it might have to do with PUN regions?
hi i'm using GameSparks for an online quiz game, i fixed every things and works fine in preview mode but when go in live mode i get this error in Unity console
GS: System.NullReferenceException: Object reference not set to an instance of an object
also this is the line that this happening :
soalatlist = _message.ScriptData.GetGSDataList("soalatList");
game sparks isnt supported anymore
its dead in the water
no tweets or updates for over 12 months
How do I go one about making a peer to peer unity game
There seems to be no tutorial about it that I can find
Clients can connect to a hosting client yes
Might require port forwarding or punch through
@languid marten Quite why you decided to DM me I have no idea, that is in contravention of the #📖┃code-of-conduct
sorry
Building our first database and setting up the scenes of our Unity project. We'll go over creating a local server environment where we can store our database and test our PHP scripts.
MAMP: http://mamp.info
Sublime Text: http://sublimetext.com
Support Board to Bits on Patreon:
http://patreon.com/boardtobits
Check out Board To Bits on Facebook:...
I was just replying to you wasn't sure if you were on still
BTBG creates a simple series about using Unity, PHP and SQL to store and retrieve player data
That video is how I did it but I have a different type of database then them because my site is designed to be like roblox
I'm familiar with their site, though I have no idea how the backend works
I have the sites full front end and backend done I just need a way to make the database connect to the game
Am I getting this right? If I want an enemy to shoot at a player, the player has to tell the server to spawn this projectile?
Say what library would you recommend for LAN stuff and dedicated servers?
Should I just make a custom implementation?
Never tried it in C# how long would you reckon it'd take?
have you done it before?
if youve implemented it before, not too long
dedicated servers arent that hard (with tcp at least; the ping can be bad, but on average its ok)
tcp for slower games, udp for fast paced games
LAN is a bit annoying
peer-to-peer could be fun, but difficult
it depends on your scope
theres obviously photon and mirror and the other one (ML?)
usually, i would say use photon?
If willing to use photon, just go for fusion
how would i create a prefab for my third person player if i have like seperate camera for it, im using cinemachine
like it's not a child of the player
so how would i make it respawnable with camera
@ancient iris spawn without camera
if character is local character, then it can use the camera
otherwise, that character doesn't touch the camera
so if i create a prefab of the player, and spawn in, how do i make it so both players get the same properties of the camera but two different camera for each prefab
//spawns without camera
if(isLocalPlayerOrSomething){
UseCamera(camera.main);
}
so like this would work for photon right
so where would i put this if state ment
it works for anything
if local player, you use the camera the way you wanna use it
like in update or something
if not, you don't touch the camera
so there is just one character moving the camera and its the local players character
@ancient iris
ok cool
one last question
if i have an animation (dodge right animation) that moves me to the right, whenever i dont use root motion it just gets stuck in that position and the camwera doesnt move with it, but if i use root motion it slides back the original positiom, how would i make it so it plays and the camera moves with it
like a dodge right
i don't ever use root motion
i have movement logic/collision/physics in character parent
and i have an animated character under it
for dodge, i'd play the animation and move the capsule myself trying to sync it to animation as close as possible
and camera just always follows the capsule
@ancient iris
if you try to design your character in a logic in a way that it can work without the animation logic, it will be more sustainable and helpful in many cases
ok wait so i would move the camera for example like to the right if i have a dodge right animation
so i suggest not letting character logic know about animation logic or animation
animation logic knows character logic but not the other way around
you dodge -> capsule moves -> camera follows capsule since it always follows the capsule
no root motion in animator
heres the problem
i have a empty game object called player then as a child i have my actual player (the prefab i got online)
and my animations are in the actual prefab
and thats your issue
i said that i suggest not using root motion
thats because your visual character moves and camera follows the parent
@ancient iris just disable the animated character
add a mesh filter/renderer to your character parent
implement the roll that way
just a capsule doing a fast move
and then worry about syncing the animation
if i remove root motion my feet sink into the the ground
you got feet IK?
my tip is
make it work with just a capsule and then use/sync the animation
this will make it easier for multiplayer logic too
you will sync the capsule part, you will not sync the animation part
animation part will be reproduced locally
character logic will not ever know about animators name or your animated body
imma try to recreate a first person sword game
fighting games require good netcode
yea
predictive you know
if im using this model
i would just position the camera do the models head
and then child it?
no
camera wont be childed
just make it follow via code
in update or late update
you will also have some more issues with your fixed update/update syncronizations
you will probably have stutters
but we can talk about that later when you get there
np
is it fine if i dm u if i have any questions later
fine
LOL ok i wont bug u
@icy thornThanks for a reply, doesn't Proton utilize a single dedicated server that you setup though?
theres cloud options and self-hosted options for Photon iirc
you would have to check
what you should do depends on what you want to do
if you want to learn how it works internally, implement your own
if you want to learn how it works in a practical sense, and then ship something, use a 3rd party solution
np
I made flashlight, I networked it over network properly and Im turning it off/on by spotlight.enable value, everything works but on another client I can't see the light, I don't know where is the problem, any ideas?
I use mirror. How i can destroy item for all players? I i write like that, if client destroy item host dont see that.
Call a command from the client to destroy it then call an Rpc from said command that has that code there
If I'm making a Peer 2 Peer game using Steamworks I would only need to replicate absolutely necessary things, like player location, rotation, health, what weapon they're holding, monster/enemy locations, rotation, and health. And things like what's in their inventory don't necessarily need to be replicated correct?
I could take player location changes and play animations locally without having to send from one peer to the other which animation exactly they are playing, inventory wouldn't be a big deal as long as whatever the player is holding or using is being replicated I would assume?
Has anyone experience using MLAPI?
hi im using photon and when the player connect the camera individually is working but whenver i move it controllers the other player, not my player, anyone know the problem, btw i used if view.IsMine
show the code
is it possible to pass a form-data to PUT Request in unity?
Hello, I am very unexperienced with Photon/PUN/Networking and have been following a tutorial series by Welton King, everything has been working perfectly with photon until we made a room list function, players can see other players rooms, the names and players connected to the room but when joining the rooms players cant see eachother nor can they see any other functions that should be called through RPC's, any help?
Ive tried skipping the whole room list functionality and just making a join create button immidietly but that still doesnt work, something messed up when trying to make the room list thingy, if there arent any problems here it might have to do with PUN regions?
PUN ships with samples that have a lobby
Remember that when you execute "CreateRoom" function it automaticlly joins to it, also make sure that t_roomName string is not null and it is the same room name as created
Im sorry, i dont really understand what youre saying
How do I use what u just said and fix the script? @river meteor
did you check if your variable t_roomName is the same as room name while creation?
hey internet can anybody help me with my movement
we take questions in advance
paste your question
i have some problems with my movement
im working on online game]
and i launch two instances of a game and when i press wasd both characters move
using photon
the code:
you arent doing anything about who processes the input, who doesnt
there should be some boolean that tells that character belongs to the local client
if that boolean is true, only then you do the input
@night cargo
there are more details to this
you should just follow a tutorial
its easier that way
Hello everyone! Can somebody tell me why objects dont destroy? I got error : "Trying to send command for object without authority"
can u sent tutorial link plz
i dunno, my favorite tuts are outdated now
can documentation help me?
well, theres some stuff about the setup
and object authorities
and spawning "player" objects
which is like the entry point for a player to send any command to server
you'd be better off seeing a tutorial imo
@night cargo
will that help me? https://doc.photonengine.com/zh-cn/pun/current/demos-and-tutorials/pun-basics-tutorial/player-networking
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!
i would wanna get my hands on a minimal, working example and understand it.
i thought tutorials are helpful for that
just my opinion
apperantly you need to have authority over that object
you might wanna put that function in players script
i call destroy on server, server have authority on all objects or no?
you shouldnt need to call command on server
@steady crater
if its server doing the destroy, just make the server call the destroying function
no commands
or you mean to make client call command for server to do the destroy
is this a client initiated destroy?
yes
this object dont spawned by player, its object exists from game start , nobody have a authority on this object , only server can destroy it if i think right
you could have like a DamageThing() command in player script
youd call that on local clients character
and that would make the server destroy the object without authority issues
@high night can i put it like this
private void Update()
if (photonView.IsMine == false && PhotonNetwork.IsConnected == true)
{
return;
}
i am sorry its been a long time i used photon
and since these are one time stuff i dont remember anything at all
if you follow a video tut, you should get some nice copy paste material to get you going immidiently
@night cargo
some capsules shooting at other capsules
thats the classic
i couldnt find anything;(
i think destroying is servers duty so authority isnt involved there
but i wouldnt know for sure
@night cargo https://youtu.be/FH8UBCM6UeI
One of the more important features of Photon you'll find yourself using more often, called "RPC (Remote Procedure Calls)". Today we'll be taking a look at this, and how it differs from direct data sending/receiving. An alternative to this is also available, called "Raise Event".
Be sure to join the discord server for any sort of help, I'm dece...
this is where i learnt
the series i mean
this is vid 4
you start from first one
2 years old so i guess its fine?
if you use pun2 though maybe look for a pun2 one
i like that its a fast paced one
doesnt go into unnecessary stuff
Just put before your code which process player input / movement if(!pv.isMine) return;
But you must first specify photonview of your player object
Each photon view have unique ID
For ex private PhotonView PV = GetComponent<PhotonView>():
Hey, pretty new to networking, I'm using Mirror.
If I want to tell if I'm the host I need to store the first client, right, since host is just the server without a client?
host client is a client that runs in same instance as server. Mirror has its own Discord for support...link is in the ReadMe and Asset Store page.
👍
Yea thats not the problem since ive also tried just skipping all of the room creation and just calling JoinRandomRoom, connects to the room, still cant see eachother nor any of the other things that should be happening over the network
Are instantiating players by PhotonNetwork.Instantinate?
Not sure, i can maybe check later but everything worked completely fine until i tried following the room creation tutorials in a video series ive been following
Something messed up around ep 43 - 44 - 45 https://youtu.be/u_mhGhXTbjs?list=PL6PsTmPNvw0eZirNDjO8dL0Y6X0ZFGaMt if that helps anything
Hey chumps! In this video I will show you how I added a room list to our fps game!!
It's gonna take a good mixture of UI and Photon callbacks to get the job done!
Join our Discord: https://discord.gg/vrErfxa
Catch up on Github: https://github.com/Kawaiisun/SimpleHostile
BFXR: https://www.bfxr.net/
Piskel App: https://www.piskelapp.com/
Audaci...
I think if they can't see each other in room I assume they are in two different rooms. Check in Unity if you have both players in object list
Bro that's so smart why didn't I think of that
Or they are instantiated locally
Alright so the players arent both in the hierarchy but t_roomName is correct
anyone able to help me trouble shoot an issue ive been having with my game. im using photon btw. just @ me or dm me if you could help me out
ok you have cs public override void OnJoinedRoom() { base.OnJoinedRoom(); if (!PhotonNetwork.IsMasterClient) return; StartGame(); }
what does StartGame(); function do?
use pastebin.org for the next time
but you dont instatinate the players in any place
you must do playerobjects as prefabs, then put these prefabs into Resources folder and then in StartGame function or OnJoinRoom use PhotonNetwork.Instatinate
So for Pun2 I added a OnOwnerChange to a script, and a targetcallback in the awake and destroy but it still doesn't work
Is there something else I need to have it receive the event for when the objects owner changes?
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.
my camera is a child of my fps controller
tip: ```cs
void Update()
{
if(!view.IsMine)
return;
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * movementSpeed * Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
} ``` this would be simpler to use in future
but I don't why controls are swapped
did you instantinated players by PhotonNetwork.Instantiate?
wait so should i change it to this
and also i did instantiate it, ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class SpawnPlayers : MonoBehaviour
{
public GameObject playerPrefab;
public float minX;
public float maxX;
public float minY;
public float maxY;
private void Start()
{
Vector2 randomPosition = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
PhotonNetwork.Instantiate(playerPrefab.name, randomPosition, Quaternion.identity);
}
}```
you can try but I shouldnt change anything
like the camera works but the im controlling the other player instead of my player
idk why
try add to your player script ```cs
public static GameObject LocalPlayer;
void Awake(){
if (PV.IsMine)
{
// Change YourPlayerClass with your player controller class
YourPlayerClass.LocalPlayer = this.gameObject;
}
}```
to my movement script right?
yea it can be to movement script
then in your SpawnPlayers class
add condition
private void Start()
{
if(YourPlayerClass.LocalPlayer == null) {
Vector2 randomPosition = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
PhotonNetwork.Instantiate(playerPrefab.name, randomPosition, Quaternion.identity);
}
} ```
what is YourPlayerClass
in this case
public class MovementScript : MonoBehavior
MovementScript?
Or am i dumb
So replace YourPlayerClass with MovementScript
Im confused
yep
add this or delete the previous code on it?
@river meteor when i tried ur thing i couldve move at all
and i got this error
Anyone with photon experience
What are the main differences between bolt and PUN
What would fit best for a small scale multiplayer game with low costs (preferably non)
So for Pun2 I added a OnOwnerChange to a script, and a targetcallback in the awake and destroy but it still doesn't work
Is there something else I need to have it receive the event for when the objects owner changes?
Could it be I'm not inheriting from the right class?
anyone can solve bugs in photon? dm me
MLAPI - The type or namespace name 'NetworkBehaviour' could not be found (are you missing a using directive or an assembly reference?)
Did you add the namespace MLAPI?
I add MLAPI.Messaging
and MLAPI networkvariable
Ok, NetworkBehaviour is from MLAPI, so add that namespace
i can't install mlapi naturally
when i enter the unity link it just does nothing
i do it through manifest
this correcly?
