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 /
This question was closed May 14, 2013 at 11:41 PM by TheDarkVoid for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by TheDarkVoid · Sep 16, 2012 at 08:26 PM · arraylistrpc

Using RPC to send a List

I want to send my player list from my server to all players, but RPC doesn't support lists/arrays. what is the best way to get around this. keep in mind that the list couldn't simply add a player to each player's list each time, because when a player leaves the game, the list would get all out of order and it would add players that are already there to new players list.

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

  • Sort: 
avatar image
3
Best Answer

Answer by whydoidoit · Sep 16, 2012 at 09:31 PM

You can use BinaryFormatter and Convert to store your list in a string - send it to the recipient and then get it back again.

I can't (for some reason I don't understand) find my previous answer to a similar question but I guess in JS it would look like this:

 #pragma strict
 
 import System.Runtime.Serialization.Formatters.Binary;
 import System.Runtime.Serialization;
 import System.IO;
 
 
 var list = new List.<SomeClass>();
 
 function Start () {
     var o = new MemoryStream(); //Create something to hold the data
     
     var bf = new BinaryFormatter(); //Create a formatter
     bf.Serialize(o, list); //Save the list
     var data = Convert.ToBase64String(o.GetBuffer()); //Convert the data to a string
    
 
     //Reading it back in
     var ins = new MemoryStream(Convert.FromBase64String(data)); //Create an input stream from the string
     //Read back the data
     var x : List.<SomeClass> = bf.Deserialize(ins);
     print(x.Count);
 }

You would send the string in data and use the second part to read it back again.

Comment
Add comment · Show 6 · 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 TheDarkVoid · Sep 16, 2012 at 09:39 PM 0
Share

i'll convert this to C# and get back to you if it works.

avatar image TheDarkVoid · Sep 16, 2012 at 09:56 PM 0
Share

thank you this works like a charm.

avatar image whydoidoit · Sep 16, 2012 at 09:58 PM 0
Share

It's a shame about needing to convert it to a string - but no chance of sending the byte array - oh well...

avatar image whydoidoit · Sep 16, 2012 at 10:06 PM 0
Share

On reflection - you could probably use Encoding.ASCII.GetString() and .GetBytes() which would make the transmission format smaller - I tend to use Convert because that works to web services.

avatar image TheDarkVoid · Sep 17, 2012 at 12:07 AM 0
Share

i dont think the transmition format matters in my case since there are only so many players per game server, and the data is only sent when a player join/leaves/gets kicked. here is a video demonstrating the server system: http://www.youtube.com/watch?v=6L5$$anonymous$$fa0wQWQ

Show more comments

Follow this Question

Answers Answers and Comments

11 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

Related Questions

A node in a childnode? 1 Answer

Dynamic Enemy Transform List 1 Answer

How can you do calculations on two lists? 1 Answer

Data overriding itself? 2 Answers

How do I check a List[0], when it's nothing? 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