Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 kag4380 · Aug 07, 2015 at 08:30 PM · networkingunity multiplayer

Network.connections.Length is always 0

I have an empty gameObject with a script that contains below code snippet.

void FixedUpdate () {

     if (isServer) {
         Debug.Log ("NCL:" + Network.connections.Length);
     }
 }

Everytime a client connects, the above NCL value stays 0. What can be wrong here?

Comment
Add comment · Show 2
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 KdRWaylander · Aug 10, 2015 at 07:53 AM 0
Share

Hi,

Try calling your Debug.Log in this message:

 void OnPlayerConnected () {
 
 }

http://docs.unity3d.com/ScriptReference/Network.OnPlayerConnected.html

avatar image kag4380 · Aug 10, 2015 at 02:06 PM 0
Share

Hey Thanks ! But, I'm a little confused here. As per documentation, a host acts as a server as well as a client. So, I was wondering where to use these server related functions. I tried using it in the player script(this script is part of prefab that's spawned across the network using Network manager) but no luck. I tried adding [server], [command] before functions but that didn't worked either. I also tried creating an empty game object & then adding a script to it that contains server related functions but that was of no use as well. I know I'm not getting a thing which should be pretty obvious :(. All I wanted to know is where should I write the code to execute server commands. In other words, what is & where is my server after I spawn my players across the network.

1 Reply

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

Answer by seanr · Aug 10, 2015 at 08:15 PM

Network.connections is part of the old/legacy network API.

If you are using UNet, try NetworkServer.connections.

Comment
Add comment · Show 3 · 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 kag4380 · Aug 10, 2015 at 08:47 PM 0
Share

That works. Thanks !

avatar image KdRWaylander · Aug 11, 2015 at 08:30 AM 0
Share

You should mark his answer as accepted :)

avatar image WickedFreaK · Mar 16, 2017 at 10:29 AM 0
Share

Thanks! And use NetworkServer.connections.Count to get a number

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UNET NetworkServer.Spawn intermittently not called on clients 1 Answer

Unity networking tutorial? 6 Answers

Local IP adress in UNet 4 Answers

[UNet] "No such host is known" error on iOS 1 Answer

UNet. Messaging not work. Please help. 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