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 uberokeer · Mar 14, 2013 at 01:31 PM · gameobjectnetworking

Destroying Netowork Player on Disconnect

Hello, Does anyone know if there is a way to access a GameObject with:

function OnPlayerDisconnected(player : NetworkPlayer) { Debug.Log("Clean up after player " + player); Network.RemoveRPCs(player); Network.DestroyPlayerObjects(player); }

I Don't have my network script attached to a player, I have it attached to a Empty GameObject Called Network Manager.

I wanted to know if i could somehow make

 player : NetworkPlayer = GameObject.Find(Cloned Prefab)

Without any errors

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

2 Replies

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

Answer by Khada · Mar 14, 2013 at 01:43 PM

The way I solve this, is to store the NetworkPlayer and PlayerPrefab in a Dictionary with one acting as Key, and the other as Value (I actually keep two dictionaries, the seconds having the Key and Value types reversed). Part of how I do this is to create the PlayerPrefab instance inside the OnPlayerConneted callback, storing it as a Value, with the NetworkPlayer argument as the Key.

This way I can just use the received/sent NetworkPlayer from an RPC to easily grab the corresponding GameObject.

Comment
Add comment · Show 5 · 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 uberokeer · Mar 14, 2013 at 01:54 PM 0
Share

Okay, I see. But what do you mean by dictionary?

avatar image Khada · Mar 14, 2013 at 02:06 PM 0
Share

Oh, you're in JavaScript (boo!) which (to my knowledge) doesn't have a built-in C#-style Dictionary container. The easiest thing might be to use 2 Unity JavaScript Arrays.

In short, when a player joins, add the NetworkPlayer to one array and the GameObject to the other, and when the player leaves, remove from both. Then you can loop through the array of NetworkPlayers, find the NetworkPlayer that matches the one sent in an RPC and use it's index value to obtains the corresponding GameObject from the other list.

avatar image uberokeer · Mar 14, 2013 at 02:12 PM 0
Share

well then...I will start looking up tutorials then because i have no idea what You just said xD yep ima noob.

avatar image Khada · Mar 14, 2013 at 02:27 PM 0
Share

If you're new, might I suggest (and other will disagree) that you learn C# rather than JS. In some ways C# can be considered harder but I would say that overall it's easier. It's harder to mess things up because it's a statically typed language as apposed to JS which is dynamically typed, and it has easier-to-use built in libraries (which give you access to things like Dictionaries) and a nicer syntax (though that's personal opinion).

Either way, I would definitely get a solid grounding in single player games before moving onto multiplayer as multiplayer games are notably more complex.

I'll leave it up to your judgement whether or not you think I've answered your question (and thus whether or not to mark it as an answer etc). :)

avatar image uberokeer · Mar 14, 2013 at 02:55 PM 0
Share

okay well I will start watching tutorials Thanks!

avatar image
0

Answer by ExTheSea · Mar 14, 2013 at 02:38 PM

I use this http://docs.unity3d.com/Documentation/ScriptReference/Network.DestroyPlayerObjects.html but I think this will destroy every Gameobject instantiated by the Player who disconnected.

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

12 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

Related Questions

How to destroy object forever? when i go to another scene and back to first, i want to that object stay destroyed! , Please !!!!  1 Answer

How to synchronize GameObjects 2 Answers

Synchronizing Game State Via RPCs 0 Answers

Does inactive Objects eat up Performance? 1 Answer

GameObject.Find only working on server? 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