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 pekalicious · Dec 06, 2012 at 01:03 AM · networkingnetworknetwork.connect

OnConnectedToServer called multiple times

Hey guys,

I'm creating a client/server game where one of the players act as a server and the other as a client.

I have one GameObject that is not destroyed between scenes and contains all RPC functions. I DO NOT create and sync it with NetworkView. I just call RPCs between client and server.

Here is the situation I'm getting into:

  • Server hosts a game to MasterServer

  • Client see it and connect to it

  • Game starts

  • Server dies (the app is closed) - All clients return to List of games scene

  • SAME SERVER PLAYER launches and hosts the app again

  • Clients see the new game, connect again

  • ------- Each client's OnConnectedToServer is now called twice

If the server dies again, host another game and the client connect again, now the OnConnectedToServer is called three times!

Am I missing something? Do I have to call something to clear.... something?

I tried the following:

 private void OnDisconnectedFromServer()
 {
     Network.RemoveRPCs(Network.player, 0);
     Network.RemoveRPCs(Network.player, 1);
     Network.RemoveRPCs(Network.player, 2);
     Network.RemoveRPCs(Network.player);
     Network.RemoveRPCs(this.networkView.viewID);
     Network.RemoveRPCsInGroup(0);
     Network.RemoveRPCsInGroup(1);
     Network.RemoveRPCsInGroup(2);
     Network.DestroyPlayerObjects(Network.player);
     StartCoroutine(LoadScene("Title"));
     Network.SetLevelPrefix(0);
 }

None of this does anything.

Thank you in advance.

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

Answer by Bunny83 · Dec 06, 2012 at 01:11 AM

"GameObject that is not destroyed between scenes". Is it possible that this Gameobject is in a scene which you load again? in this case you will have the gameobject several times. DontDestroyOnLoad just prevents that the object is destroyed. When you load the scene again you will end up with another GameObject.

If you want to use such a manager object, the best thing you could do is create a loader scene (which should be the first scene) and place your GameObject in there. NEVER load this scene again. All you do in Awake of the Manager script is loading the mainmenu scene (or what ever).

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 pekalicious · Dec 06, 2012 at 01:34 AM 0
Share

Words cannot describe how thankful I am! This solved a lot more problems than this! Thank you thank you thank you thank you thank you thank you thank you thank you thank you.

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

10 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

Related Questions

Problem with basic networking... 1 Answer

Networking two separate PCs on the network 1 Answer

Network ipAddress always 0.0.0.0 on PC, correct everywhere else. 3 Answers

Why is the Network.Connect does not work with "hostdata" 0 Answers

New multiplayer setting broke Network Lobby 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