Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Pentos60 · Apr 02, 2013 at 10:28 AM · networksynchronization

Synchronisation from client to server

Hi all,

I'm developing a network application and I experience a trouble in the synchronization from server to client.

When I move an Object on the server side , this Object move on the client side. But when I move an Object on the client side it doesn't move because the position is synchronize from the server.

I would like to know How I can make a synchronization server/client and client/server.

I found this article : http://answers.unity3d.com/questions/289324/networkview-control.html

But I really don't have a lot of knowledge in networking and I don't really understand where I have to put this code?

I define the network like this :

 if(server)
    { 
       Network.InitializeServer(4, listenPort, true);
       for(var obj in FindObjectsOfType(GameObject))
       { 
          obj.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
       }
    }
 
    else
    { 
       Network.Connect(remoteIP, listenPort);
    }
 

So My question is : Is my definition of the network good?

How can I allowed the synchronization client/server and where have I to put the code.

Thank you in advance for all the advice you could provide me because it's very difficult to find informations about this subject.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Dunkhan · Apr 02, 2013 at 04:53 PM

I had this problem a while back. The client that allocates the viewID is recognised as the owner and send all updates to the view. You can simply make the client allocate the viewID from the start but then the server won't be able to move it. If you want both client and server (and also multiple clients) to be able to take control of an object you have to reallocate the viewID at runtime. You can not have two clients moving the object at the same time but they can take turns. This is the code I used, these two functions need to be on a script attached to the object, and becomeOwner() on needs to be called by any client that wants to start manipulating the object.

 function becomeOwner()
 {
     var viewArray = this.gameObject.GetComponents(NetworkView);
     var objView : NetworkView = viewArray[0];
     var newObjID = Network.AllocateViewID();
     
     networkView.RPC("changeOwner", RPCMode.Others, newObjID);
     
     objView.viewID = newObjID;
 }
 
 @RPC
 function changeOwner(objID : NetworkViewID)
 {
     var viewArray = this.gameObject.GetComponents(NetworkView);
     var objView : NetworkView = viewArray[0];
     objView.viewID = objID;
 }

Note this will only change the first networkView on an object, if there are multiple views on an object you will have to do this on each one.

Bear in mind this is an insecure way of doing things, if you give clients control over the network views they may use it to do illegal things, ie. cheating. The secure method is for the client to send their controls to the server and have the server move the object. This means the server can check if moves are legal before doing them.

Comment
Add comment · Show 2 · 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 Pentos60 · Apr 08, 2013 at 05:42 PM 0
Share

Hi Dunkhan, Sorry for the delay of my end, I've been rather busy... Thank you so much for your answer.

I tried your code but I have two error :

View ID AllocatedID: 0 not found during lookup. Strange behaviour may occur

Received state update for view id' AllocatedID: 0' but the NetworkView doesn't exist

I can move the object from the client side but it does not synchronize on the server side.

Have you any ideas of where this where this problem comes?

Thanks you again for your help.

Regards

avatar image Dunkhan · Apr 12, 2013 at 02:17 PM 0
Share

I am sorry but it is difficult to work out what those errors mean specifically without more information. Those errors you are receiving relate to update information being sent from a network view on one side, that does not exist on another. Did you copy the code to both the client and the server? Have you set any view ids in the inspector?

It may be easier for you to simply use the second method. Put a script on the player and serialise all their control input to the server, and have only the server move the object.

Consider using pastebin to post sections of code and more detail from the error messages. Also a brief description of what your project is supposed to do in the end often helps in working out which network solution will suit you.

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

12 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

Related Questions

How fast do Syncvars synchronize? 1 Answer

Multiplayer Animating 2 Answers

Networking Sync SetActive Not Working 0 Answers

Sync animaor of child prefab 0 Answers

network communication: How to make sure that information is in sync without server? 0 Answers


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