• 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 kobra.28 · Aug 10, 2014 at 09:28 PM · c#networkinginstantiatesocket

Best way to Instantiate and synchronize 300 000+ GameObjects over LAN?

Hi, I completely new to Unity (couple of days) and I made a simple game with a map containing plenty of Sprites (2 types). I want the game to be played on computers through LAN and I did network discovery of hosts/broadcast of server and synchronizing players positions.

Now I need to figure out how synchronize the map; both client and server have all assets. First how to "transfer" the map created by server to clients - should I use FOR I IN RANGE(0,300000){Network.Instantiate();} or that would be slow? Or should I send t$$anonymous$$s map as an array through System.Net.Socket and create TCP socket for that manually - that would be very fast actually, but I want to know how fast/slow is Network.Instantiate, as I would use it for convenience.

Also, some sprites get destroyed, let's say 40/second on average, so should I do Network.Destroy(GameObject)? Or again send an array with the destroyed GameObjects, but how? Can I send directly a GameObject? or just position, or what? How the other computer can know w$$anonymous$$ch GameObject to destroy based on e.g. position? It needs to be fast, too. Thanks for your advice.

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 calmcarrots · Aug 10, 2014 at 10:45 PM 0
Share

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by mediumal · Aug 11, 2014 at 12:41 PM

T$$anonymous$$s doesn't sound too hard, actually, assuming the clients already have the map or a way to generate it from a small set of configuration parameters. Definitely don't use Network.Instantiate() for each tile.

Setup

Use Network.Instantiate() to create a single network manager object that will contain your management RPCs.

Map Creation

Have the server call a single RPC to give the map to the clients. Instead of sending 300,000 tiles worth of data, instead just send the name of the map file to load or, if you are making the map procedurally at runtime, send the random seed and identifier of the algorithm used to create the map. Then create the map just as you would on the server (without using Network.Instantiate()).

Destruction

Call another RPC each time you want to destroy a tile, passing its identifier or coordinates. Then find the tile using the parameters and use Object.Destroy() instead of Network.Destroy().

You could also create new tiles on the fly using a t$$anonymous$$rd RPC.

Bulk Data

40 destruction RPC calls a second might not be too bad, but you could always record the destruction and then send them out in a bulk RPC call. To send a lot or variable amount of data in an RPC use t$$anonymous$$s technique: http://answers.unity3d.com/questions/54424/sending-bulk-data-via-rpc.html

It could also be used to send all your map data if there is no way to generate the map on the client without sending info on all tiles.

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 kobra.28 · Aug 11, 2014 at 02:39 PM 0
Share
avatar image
0

Answer by Entwicklerpages · Aug 10, 2014 at 11:06 PM

Ohhhh .... wow.....

I am not sure how simple game and 300 000 network instantiations can work together but okeee.......

I don't t$$anonymous$$nk you should use Network.Instantiate. It should be used for Players or Object taht must be synchronized and Instantiatet in runtime.

The idea with the TCP Sockets might be the best but I t$$anonymous$$nk it isn't .... let's say... sexy.. if you also use the Unity Networking. I wouldn't mix them. Perhaps you can serialize your map to a string and send t$$anonymous$$s string over network (perhaps as a RPC call - not sur if t$$anonymous$$s is best option - depending on the size of the final string). It all depands on the kind of map you have. If ist is only a "binary map" it would be easier. So every tile can be t$$anonymous$$s sprite or another sprite. So you only must go thru your map and put them to a long binary ... t$$anonymous$$ng. T$$anonymous$$s t$$anonymous$$ng could be encoded as base64 and maybe you try some compression algos out.

One last t$$anonymous$$ng. I don't know how your map is built. Because you wrote about sprites I t$$anonymous$$nk it is a 2d-tile map. Having 300 000 single sprites could end with performance issues. If they are in the same texture Unity can batch them to gether to give you an performance boost.

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 kobra.28 · Aug 11, 2014 at 10:48 AM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

C# TcpListener is reachable only from local 1 Answer

Multiple Cars not working 1 Answer

[Photon] Looking for example code for late joining clients syncing instantiated game objects that don't exist in the base scene 0 Answers

Instantiate object from client doesn't work on server. 1 Answer

Instantiate object from client doesn't work on server. 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