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 KdRWaylander · Mar 12, 2015 at 04:10 PM · networkingdestroydisconnect

Destroy its own instantiated objects when leaving server

Hi !

I have a quick question here :)

I made a little demo where i have a server and one client, on my own computer (127.0.0.1), i just connect to the server, pop some little cubes and then disconnect. Right now, eveything is working. So why am I here ? When my client leaves, i ask my server to clean up the mess and destroy everything the client did:

 void OnPlayerDisconnected (NetworkPlayer player){
         Network.DestroyPlayerObjects (player);
         Network.RemoveRPCs (player);
 }

This is working but my client still has the cubes in its scene when i disconnect so if i go back on the server with the same client, without quitting and launching the exe again, i find myself with an empty server -as i can expect with the few lines of code just above- BUT with a client with all the previous cubes i popped. So when i pop more cubes, the server thinks there is 1 cube while my client has in fact >1 cubes.

I'm trying to find a proper way to destroy what one specific client did in my scene, without having to mark it on a list everytime i pop something and then use Object.Destroy() on all the items of the list, something that would clean up without wondering what or how much, like the server is able to do, something equivalent to that:

 void OnDisconnectFromServer(){
     DestroyOwnObjects ();
     RemoveOwnRPCs ();
  }

Cheers :)

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
0
Best Answer

Answer by KdRWaylander · Mar 17, 2015 at 02:32 PM

I found part of my solution: for the objects i instantiate with Network.Instantiate, adding this prior to disconnect will work:

 Network.DestroyPlayerObjects (Network.player);
 Network.RemoveRPCs (Network.player);

But it doesn't work with objects that i loaded on the server only ! When i connect my client to the server, pop one cube on RPCMode.AllBuffered, one cube on RPCMode.Server and then disconnect, my server will have one cube (instead of two like in my previous post), even if i do have these lines in my server script:

 void OnPlayerDisconnected (NetworkPlayer player){
     Network.DestroyPlayerObjects (player);
     Network.RemoveRPCs (player);
 }

In addition, with the new lines of code, my application seems less stable and crashes from time to time - not sure it is related, but who knows ?

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

1 Person is following this question.

avatar image

Related Questions

Why dont this script work? 1 Answer

Unity High Level Api Random Disconnect 0 Answers

Server disconnect message after closing connection 0 Answers

How to Quit() Unity application when using sockets? 1 Answer

[UNET]Disconnecting from network doesn't destroy the player. 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