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 Xullripper · Jun 01, 2012 at 03:06 AM · networkloadlevelclient

Network: Connect & LoadLevel on client side (bugs)

Hi

I've been searching for a couple of hours now on this problem:

I have a GameObject Administration with 2 scripts attached. 1 with this code, so it won't be destroyed during the game:

     void Awake()
     {
         // Don't destroy the object, so it can be used in other scenes
         GameObject.DontDestroyOnLoad(this);
     }

The other scripted is my own networkScript.

In the mainmenu (scene), you can choose to be a server or client and depending of the choice, the game will load the Server or Client scene. In the client scene, I have this in the OnGUI() of an attached script:

         // "Connect to server" button
         if (GUILayout.Button(txtBtnConnectToServer))
         {
             ConnectToServer();
 
             Application.LoadLevel((int)levelToLoad_ConnectToServerBtn);  
         }

ConnectToServer() calls Network.Connect("ip", "port") in the networkScript (that is attached to the administration object) This works fine. Server and clients can see each other, attack each other...

Now, as you can see, it's possible that the client is still connecting, but already loads the next level. So what I've tried:

In the Client scene, I've changed the code to this:

 // "Connect to server" button
 if (GUILayout.Button(txtBtnConnectToServer))
 {
     ConnectToServer(); 
 }

In the networkScript (attached to Administration), I have this:

void OnConnectedToServer() { Application.LoadLevel((int)levelToLoad_ConnectToServerBtn);
}

This doesn't work correctly. All players can see the new spawned player, but a new player can't see the old players already connected to the network. I started looking in the editor (as a client). If I connect, I see the spawned players for a second, than loads the level, and removes all the old players in its own scene.

I don't use OnConnectedToServer() in other scripts. If I change the code from the server side in something that's equal to this (but with OnServerInitialized()), it will work for the server.

I also tried to bind Application.LoadLevel((int)levelToLoad_ConnectToServerBtn) to a key. Just let the client connect to the server, wait a few seconds, and pressed the key.

It seems that Application.LoadLevel() removes all spawned network objects in your own scene?

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 Xullripper · Jun 01, 2012 at 05:40 AM

Ok, after another couple of hours debugging and testing, I finally found the problem!

The player object (and it's weapons, inventory...) that spawns in the network needs the DontDestroyOnLoad(this) too.

I think this solution was obvious, since every connected player have their own instances of spawned network players in their scene. LevelLoad() deletes all objects in your own scene, so the instances of spawned network players too.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Buffer RPC until I have the right scene loaded 0 Answers

Trying to manage local network users. (5.1.0) 1 Answer

Trouble with Server Client connection 1 Answer

Is there any difference calling Network.Disconnect or Network.CloseConnection from client? 1 Answer

Network.Instantiate fired from client AND 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