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 NinjaWalrus · Oct 30, 2012 at 12:11 AM · networklengthdoes

Does Network.connections.Length include itself?

I am using Network.connections.Length to display the number of players in an online game, but when I start a server (As the server) I am told there are no players in the game, even though I am in it. Is this because Network.connections.Length does not include itself, or is it more likely a problem in my coding?

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
2

Answer by Bunny83 · Oct 30, 2012 at 12:16 AM

Network.connections, as the name said, only holds network connections. When the server is alone, he's not connected to anyone, so the Length is of course "0". When one player joins there is one connection from this new player to the server. If three clients joined the server there are three connections.

Keep in mind that Network.connections on clients will always be either "0" or "1", nothing else. A client can only be connected to one server at a time. Network.connections can be used to count the player on the server, but there's no way to get this information on a client. A client has no idea how many other players are connected to the server. You have to count the players on the server and send this information explicitly (via RPCs) to your clients.

Comment
Add comment · Show 4 · 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 NinjaWalrus · Oct 30, 2012 at 12:19 AM 0
Share

Thanks! It all makes sense now!

avatar image BlackPanda · Mar 10, 2015 at 09:00 AM 0
Share

hey @Bunny83 I want to get server networkplayer from the client. So shouldn't I just use Network.connections[0] to get the server player from the client?? Somehow it's not working for me. :(

avatar image Bunny83 · Mar 12, 2015 at 05:09 AM 1
Share

@BlackPanda: Yes, if the client is connected to a server then Network.connections[0] represents the server player on the client machine. $$anonymous$$eep in $$anonymous$$d that not all fields of the NetworkPlayer has to be set. You can use that reference to send RPCs to that player (RPC$$anonymous$$ode.Server would do the same), or check a NetworkView if it's owned by the server player.

If you want to make other information available to other players (like the GUID) you have to use RPCs to propagate that information to the others.

If you have more questions you might want to ask an actual question ins$$anonymous$$d of posting a comment here ^^.

avatar image BlackPanda · Mar 16, 2015 at 05:20 AM 0
Share

@Bunny83 thanks :) That's okay, I resolved the issue.

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

10 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

Related Questions

RPC , string parameter is sent, but length is 0 1 Answer

How to do a TCP Server? 4 Answers

Can't send RPC function since no connection was started 1 Answer

indie db hosting woes 1 Answer

What could be causing error: "Receiving NAT punchthrough attempt from target ############ failed" 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