- Home /
UNet Portal 2 Like Object Interaction Client to Server
Hello. I'm working on a 3D puzzle platformer cooperative game much like Portal 2 using UNet 5.3.2f1. I have reached a point in development where I need to sync a player picking up and moving around an object across the client and server. However, this functionality has become a huge roadblock as I have been tackling it for the past couple of days without success.
Currently, when the host picks up an object, it works perfectly as expected; the object moves and that is reflected across on the client side. Here's links to gifs of:
Host View Picking Up Object:
https://giphy.com/gifs/VEWsUVkkzKLmM
Client View Watching Host Pick Up Object:
https://giphy.com/gifs/S13UXAbsSDSEg
However, the problem comes in when the client tries to pick up an object. When they try to pick up an object, the changes are not synced to the host and the object's position is stuck where it is on the host. Here's links to gifs of:
Host View Watching Client Pick Up Object:
https://giphy.com/gifs/10YqdzU2MWx6Ao
Client View Picking Up Object:
https://giphy.com/gifs/WxgmxnhneQP0k
Here's my PickUpObject script on pastebin if that will be helpful: http://pastebin.com/Y5Se9Vft
Sorry that it's a bit messy and cluttered with comments. That was from hours of trying to get it to work.
How the scene is set up:
The script above is attached to the root of the player objects that are being controlled
The player objects have NetworkIdentities set to Local Player Authority and NetworkTransforms syncing Rigidbody 3D
The object has a NetworkIdentity set to Local Player Authority and a NetworkTransform syncing Rigidbody3D
The object IS NOT a Registered Spawnable Prefab. From my understanding of the UNet documentation, an object that exists in the scene with a NetworkIdentity attached to it is a Scene Object. This is spawned automatically by the NetworkManager after the scene loads with NetworkServer.SpawnObjects(). From this documentation.
My desired behavior is having the client pick up the object naturally and having those changes synced to the host. Just as you would expect from a game like Portal 2. I'd like to just be able to build scenes and levels by placing the objects around the level, like you would a single player level.
I have tried googling for hours only to meet dead ends and "solutions" that had no effect. It would be amazing if somebody could help me with this as I've been working on it for days yielding no results.
Thank you!
Have you found a solution for this? I have pretty much the same issue.