Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 crezax · Aug 26, 2016 at 01:02 AM · networkingmultiplayer

Detecting who left UNET game

I'm creating a 2 player online game. I'd like to show a 'your opponent left' information when one of the players leaves.

I understand I can use OnClientDisconnect to detect that client disconnected from server. But the client doesn't know if it's because server crashed, lost connection etc, right?

Same with the server side. I can use OnServerDisconnect, but how can I know that the player disconnected from server, because he closed the client, lost connection etc, rather than server losing connection?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by NFMynster · Aug 26, 2016 at 08:46 AM

This describes what you need That way you can detect the reason for a disconnect.

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 crezax · Aug 26, 2016 at 08:52 AM 0
Share

Isn't that used for the legacy network system rather than UNET?

avatar image NFMynster crezax · Aug 26, 2016 at 10:43 AM 0
Share

Yes sorry, I just ran into this issue and looked at the source code for the networkbehaviour. It seems as there is no call connected to when the player disconnects from a server. Ins$$anonymous$$d you can create "OnDestroy" that will be called no matter how your client got disconnected.

avatar image crezax NFMynster · Aug 26, 2016 at 12:25 PM 0
Share

As I mentioned in the question, OnServerDisconnect() is called on server, when client disconnects and OnClientDisconnect() is called on client, when connection is lost. Those are functions of Network$$anonymous$$anager.

$$anonymous$$y problem is understanding the reason of disconneciton.

avatar image
0

Answer by DiegoSLTS · Aug 26, 2016 at 03:21 PM

I couldn't find any way to detect the desconnection reason. In our game, when a client wants to leave a match it first executes a Command, so the server knows that the client wanted to disconnect. If the connection is lost and the Command didn't run, then the client must have lost connection.

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 crezax · Aug 26, 2016 at 03:59 PM 0
Share

That doesn't really solve an issue of host losing internet access. I wouldn't want to show 'your opponent left, you win' in case hosting player loses connection, for example turns off Wi-Fi.

I could potentially try to check if there is working internet connection in that case. Then have separate logic when playing in LAN. I just hoped there was some cleaner way to do that.

avatar image
0

Answer by glitchers · Sep 06, 2016 at 04:08 PM

As far as I am aware there isn't any built-in functionality to do this.

I do this for detecting if the server was closed / the client lost connection. Here's a small flow of how I do it.

Flow

I differentiate between the game over state and the game state. If the game has been set to "game over" either through a win condition or the game duration elapsed then when the client returns to the lobby this is valid. Similarly connecting to the lobby via the menu is valid.

Whenever the 'offline' scene is loaded if the previous state wasn't valid for the scene to be loaded I determine that a disconnection. The client isn't aware of what kind of disconnection that is ( server closed, crashed, etc) but for my purposes it's sufficient.

When the host disconnects or loses connection to the clients Unity's NetworkLobbyManager it loads the lobby scene. This is the same as NetworkManager loading its offline scene. They are identical if you look inside the code.

Easiest way to do it is set a static flag when the game is loaded and setting the opposite in the menu and on game end.


screen-shot-2016-09-06-at-165746.png (32.9 kB)
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

93 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Multiplayer/Networked - Is there a way to have server execute animation events? 0 Answers

Using Morph3D Content Packs with Unity Networking 0 Answers

Multiplayer Password 0 Answers

Multiplayer Networking for Android 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