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
0
Question by Anton Petrov · Nov 09, 2010 at 09:10 AM · networkinginstantiatenetworklevelloadlevel

Networking: how to sync NetworkViewIDs for level objects on peers?

I think this is a common issue.

I have a level with game objects. How am I supposed to load this level on remote peers so that game objects with NetworkView components were in sync?

To sync NetworkViewIDs you should use Network.Instantiate() or write custom instantiation code which will use Network.AllocateViewID();

I do not like Network.Instantiate because all my objects are already instantiated when level loads. Am I supposed to destroy game objects and recreate them with Network.Instantiate? This is stupid.

And how can I use AllocateViewID? I should invoke an RPC call to send my IDs and to tell clients which game objects these IDs are related to. And how can I specify an exact object via RPC?

EDIT: Do you have an idea how Network.Instantiate internaly works? This method should use an RPC call to send NetworkViewID to all connected peers and how it tells what object to instantiate?

Comment
Add comment · Show 3
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 Swift_On_Fire · May 19, 2012 at 11:07 PM 0
Share

I have a related question. When a new client connects to the server, how do you tell the client to load all the game objects already Network.Instantiated on the server, prior to connect?

I have used a C# version of this code: http://unity3d.com/support/documentation/Components/net-NetworkLevelLoad.html

However, the load is not happening.

avatar image Bunny83 · May 19, 2012 at 11:59 PM 0
Share

@Swift_On_Fire: It's not really related and can't be answered that quick. In the OP case all NetworkViews that are part of a scene already have unique IDs. There are different versions of NetworkViewIDs. Beside the usual ones there are also scene-based view ids which are automatically in synch when you load the same scene. Usually when you send the loadlevel RPC as buffered RPC it should be the first thing that a new client is executing. All other things that has happend before the new client has connected are executed in the same order as long as they has been sent via buffered rpcs. Network.Instantiate uses a buffered RPC internally, so all those instantiate calls should be executed automatically.

If you're not familiar with the concept i strongly recommend to do some simple tests on your own. Networking can get really complex and it's hard to help anyone without having the full project.

If you think you really have a clear question that can be answered with a clear answer, post a real question ins$$anonymous$$d of commenting on this one.

Just a last hint: You don't have to use Network.Instantiate. You can handle the instantiation yourself, but you have to keep a list of all objects that have been created dynamically and tell a new client about them via RPCs, but as already said that's getting by far too complex for a short answer.

avatar image Swift_On_Fire · May 20, 2012 at 12:09 AM 0
Share

@Bunny83 Thank you for the suggestion. I do have a lot to learn about Unity networking. I did not realize that buffered RPCs get executed on a new client that way. I will go learn about buffered RPCs.

As for posting, I had posted the question prior, but no one answered.

4 Replies

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

Answer by PrimeDerektive · Jan 08, 2011 at 05:41 AM

Network.Instantiate works fine, if you clean up all the buffered instantiations. Network.Destroy() does not get buffered like Network.Instantiate, but you could just put a Network.Destroy() call in a buffered RPC call, and then you're golden. (See this answer for more info)

Otherwise, try to do things authoritatively, by spawning them on the server (so they are always owned by the server) and manipulate them from the server.

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
0

Answer by Leepo 1 · Nov 18, 2010 at 01:59 PM

Yeah allocating id's yourself gives you a bit more control than using Instantiate so you should probably go for the manual allocating. You do indeed to pass and assign the manually allocated viewid's on every client (and the server).

You need one scene networkview to transfer this (or a Network.Instantiated networkView).

I always have one gameobject which I call GameManager or GameSetup that has the games GUI and gameplay scripts on it. This also has a networkview which I use to set up the game and pass the allocated networkviews around with.

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
0

Answer by Dreamside · Oct 31, 2011 at 06:29 PM

i think your synch problem is not related with instantiating gameobjects.What i have done is this: Each peers loads scene but wait for server authentication.When server player loads it sends peers a int parameter that indicates time for loading.Peers receive this call and apply this equation :wait time=(parameter sent by server)-(package time stamp).all peers calculate this including server and when wait time is over they start game simultaneously.I have tested this loading approach with 5 sec network latency and each peer has different hardware for level load.When level loaded, i see that in a 1mbit connection while all players were active and average package rate was 1k/sec in whole network, there was a 20ms latency in all packages.What i mean is this:assume an object named obj receives update from a peer with a latency of 20ms.By the way in my networked game while i was testing this,there were nearly 2k gameobjects with networkview.

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
0

Answer by Dreamside · Oct 31, 2011 at 06:29 PM

As an answer to your question in EDIT, when you attach a networkview to a game object it has a unique id as you mentioned.When you use network.instantiate it calls a rpc in peers wtih a parameter which indicates related gameobjecs->networkview->networkviewid.Built in network handler gets this message and find the prefab which has same id.Then instantiates it.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unet NetworkServer.Spawn() not working 5 Answers

Players Not Showing 0 Answers

Architecture for a network game- problems with events 0 Answers

How can I spawn a GameObject on all players in my multiplayer game? 0 Answers

Networking-multplayer issue 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