How to sync position using new unity transport?
Hi all. I`ve got a problem. I`m trying to learn multiplayer LLAPI "Unity Transport" from official site (https://docs.unity3d.com/Packages/com.unity.transport@0.2/manual/workflow-client-server-jobs.html). I`ve already implemented jobified client and server by these lessons. And place where I`m stuck is syncronizing transform of object. I created script "SyncObject", where on transform position changes, I send message to the server, which sends message to other clients. And it`s okay, clients receive message with right coordinates, but I don`t know how to send information about WHICH object was moved. I thought about GetInstanceId() but I think it will not be the same between all clients (I`m not sure, didnt tested it). Also i thought about implementing custom id system with guids and such stuff, but it also will not be the same between clients. Send object`s name is also silly, because i can have multiple sync transforms with same name. Can anyone suggest what is the best way to do it?
Answer by destructor465 · Apr 12, 2020 at 09:17 PM
I think best way would be to first spawn object on the server, then send it's position together with the server assigned ID to the client(you can just increment ID for each object from 0 or use some other algorithm) and then client spawns that object and assigns received ID. Basic idea is that object ID is shared among server and client. And so if your server moves object somethere it can send object ID together with the new coordinates, based on received ID, client finds object and moves it where it should be. It can be done vice-versa - client spawns objects, assigns ID and sends it to server, but I'm not sure if you want to trust client that much.
Your answer
Follow this Question
Related Questions
Photon synchronization on different devices failes 0 Answers
Game Manager singleton doesn't sync across the network 1 Answer
Network enemy spotting 0 Answers
How to Update Objects Sprite to the Network 1 Answer
Problems syncing players in multiplayer 0 Answers