Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by VerneVision7891 · Jan 22, 2019 at 03:44 PM · networkingnetworksynchronization

Synchronizing game object across clients

Is it possible to have a pre-existing gameobject, that is controlled via script, and synchronize its position and rotation for all clients. If yes, then how can I do it?

I'd like to have an object that already exists in the scene (I can't spawn it, it has to be an already existing in the scene game object), control its position and rotation via script on the server and have all the clients see the change in its position and rotation. How can I achieve that?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hadar_zaguri · Oct 26, 2020 at 11:21 AM 0
Share

Did you find a solution?

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by VerneVision7891 · Jan 23, 2019 at 11:06 AM

Ok, so I approached the problem differently. Instead of using Network Transform I wrote my own script. Firstly, I wrote a short script to disable on all clients the component moving the object. Then, I wrote the script to send position and rotation from server to clients:

 public class NetworkShareTransformData : NetworkBehaviour
 {
     [SyncVar] public Vector3 currentPosition = Vector3.zero;
     [SyncVar] public Quaternion currentRotation = Quaternion.identity;
 
     [ClientRpc]
     private void RpcSyncPositionWithClients(Vector3 positionToSync)
     {
         currentPosition = positionToSync;
     }
 
     [ClientRpc]
     private void RpcSyncRotationWithClients(Quaternion rotationToSync)
     {
         currentRotation = rotationToSync;
     }
 
     private void Update ()
     {
         if (isServer)
         {
             RpcSyncPositionWithClients(this.transform.position);
             RpcSyncRotationWithClients(this.transform.rotation);
         }
     }
 
     private void LateUpdate()
     {
         if (!isServer)
         {
             this.transform.position = currentPosition;
             this.transform.rotation = currentRotation;
         }
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by tormentoarmagedoom · Jan 22, 2019 at 04:02 PM

Good day.

I think you need to watch some basic tutorials about networking and multiplayer. You are asking one of the basics... Spend 3-4 hours with some "boring but important" tutorial before commence, it will help you a lot!

PD: The easy solution is make the server to move the object and transmit the position to clients. IT's a component called Network Transform.

PD2: Spawn an object in the network is not the same as instantiate, In this context, spawn means something like "make everybody aware that this is a object in the network".

Good Luck!

Bye!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image VerneVision7891 · Jan 23, 2019 at 09:37 AM 0
Share

$$anonymous$$y problem is that I can easily use the Network $$anonymous$$anager and spawn an object from a prefab with a Network Transform but when I use a game object existing in the scene ins$$anonymous$$d of a prefab I can't get it to work.

Firstly, I set up a game object with the Network $$anonymous$$anager and Network $$anonymous$$anager HUD. When I put the prefab with a Network Transform in "PlayerPrefab" field, I could easily have a game object with a movement synchronised between server and client - I move the object on the server and see the movement on both the server and the client.

Can Network $$anonymous$$anager only work with prefabs? Because when I have in my scene a game object with Network Identity and Network Transform, and I move it on the server, it's only moved on the server, but not on the client. I assume that I'm missing something but I don't know what.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

169 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Networking Sync SetActive Not Working 0 Answers

How fast do Syncvars synchronize? 1 Answer

How to call [Command] on Client in UNet 1 Answer

How to sync variables with UNET 3 Answers

Load Previously Instantiated Network Objects 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges