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 ParametricAvocado · Sep 19, 2013 at 07:31 PM · networkingbugnetworkviewnetwork.instantiate

Weird network spawning bug.

About a week ago I started investigating Unity's networking system and did quite some progress but I don't want to go any further until I solve this strange behavior;

I created a pretty simple scene with a floor and a little cube, it has 4 different spawning spots from where the player's cubes come from when clicking the "Spawn" button.

Everything is fine about creating a game and having other players connect, all this achieved by using the MasterServer to register any games that are created.

The problem comes when a client disconnects and then rejoins the same game room. When this happens, the host of the game sees everything normally, but the other user who just rejoined will see an older copy of his cube even if he did not yet hit the "spawn" button. Seems like the host is holding some kind of residual instance information which the client interprets as an order to spawn cubes that are not actually there, also checked those mystery cubes' NetworkView and they are not owned by neither host nor client...

I think there might be some way to absolutely rid the host's room of any data related to the player that just disconnected, but using Network.DestroyPlayerObjects(player) doesnt seem to be enough. I also tried with something like this:

 void OnPlayerDisconnected(NetworkPlayer player) 
 {
   foreach(NetCubeContoller ncc in FindObjectsOfType(typeof(NetCubeContoller)))
   ncc.Terminate(player);
 }

Where NetCubeController is a script attached to each player cube and Terminate() destroys the entire GameObject (not just the script, double-checked for that).

As I said, that works for the player that hosts the game, but the original owner of those cubes will keep getting ghostly instances of his past self each time he reconnects to that same game room.

NetworkController.cs

NetCubeController.cs

The "game" can be tested here. Once Unity's test MasterServer is up again.(seems to be offline right now) To reproduce the bug simply open two tabs with the game, host in one and wait until the room appears listed below the menu in the other tab.

Once connected(as client), spawn a bunch of times, disconnect and connect again, and there they should be, phantom instances.

Thanks in advance for any advice.

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

Answer by ParametricAvocado · Sep 20, 2013 at 12:41 AM

So I finally found what the problem was.

When a player disconnects, not only does the owner of the room have to destroy the instances owned by that player but also the RPC calls, that's why the orphan cubes spawned as soon as a player reconnected.

Networking is so very much easier in Unity that I overlooked the most basic thing.

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

Not that it applies to every case, but for now it's a solution.

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

15 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

Related Questions

OnNetworkInstantiate is never called 1 Answer

Getting this error when using Network.Instantiate 0 Answers

Network, Builds wont move 1 Answer

Network.Instantiate and NetworkServer.Spawn not working 2 Answers

Proper if condition for network view 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