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
0
Question by MiniForge · Jan 12, 2015 at 06:37 PM · multiplayerserverrpcdisconnect

Multiplayer - Handling players leaving

What is the proper way to handle a player leaving a server during a game match? Currently, I have the OnPlayerDisconnected method as follows.

     void OnPlayerDisconnected(NetworkPlayer player){
         Network.RemoveRPCs (player);
         print ("Player has left. Destroying their objects");
         Network.DestroyPlayerObjects (player);
     }

However this still throws the error Couldn't send RPC function twice after the player leaves. The RPC that it is failing to send is a RPCMode.All from the host.

Edit: When a player leaves, the host still tries to send a RPC to the disconnected player for about two frames. Is there any way to stop the host's gameobjects from sending the RPC's to the objects that will soon be disconnected

Comment
Add comment · Show 4
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 mattyman174 · Jan 13, 2015 at 08:31 AM 0
Share

You should be cleaning up the players assets before you remove them.

avatar image MiniForge · Jan 13, 2015 at 09:02 PM 0
Share

What is a good way to go about doing that? Tried google searching for a bit about cleaning up assets and had no luck :(

avatar image mattyman174 · Jan 13, 2015 at 10:16 PM 0
Share

I mean just swap the function calls around. Your removing the player first, then cleaning up their assets, you should do it the other way around.

  void OnPlayerDisconnected(NetworkPlayer player){
 print ("Player is leaving. Destroying their objects");
 Network.DestroyPlayerObjects (player);
 Network.RemoveRPCs (player);
 }
avatar image MiniForge · Jan 14, 2015 at 08:25 AM 0
Share

Does RemoveRPCs, remove rpc's being sent from the player and ones being sent to the player?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by skylem · Jan 13, 2015 at 10:26 PM

im fairly certain ur code just needs to be called in a different order Your trying to remove ur rpcs while ur object exists so it is most likely still sending some before it is destroyed swap ur line

 // this way we destroy the player then remove any of the rpcs he   // created, Otherwise it will send rpcs after the RPC RemovalProcess // in that tiny window of time between the destroying and removal.
 Network.DestroyPlayerObjects (player); 
 Network.RemoveRPCs (player);

but if that doesnt work try checking that the networkview component still exists before calling the RPC, IE if(networkView != null) {

 }
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 MiniForge · Jan 14, 2015 at 01:08 AM 0
Share

I have tried both of these now and tried switching the order around with no luck.. Is there a way to send a RPC without it wanting a response? Im thinking of a broadcast like a UDP packet would do, compared to a TCP packet. A RPC that waits for no response. So I would just broadcast the last RPC or broadcast a RPC that I'm going to disconnect the player and the network view should be set to null.

The current RPC I am working with that is throwing the error--It's the "idle" animation for my character. So it is being called every frame that i'm not moving basically

Another thought I came up with, is having the "quit" button send an RPC. But I think that would run into the same 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

27 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

Related Questions

Unity networking tutorial? 6 Answers

Interchange player names in Multiplayer game 1 Answer

Using animator with RPC 1 Answer

How can I send a mouse click to a server using an RPC? 0 Answers

Is server the sender of RPC? 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