Search Unity

GameObjects with NetworkIdendity are getting disabled

Discussion in 'Multiplayer' started by Ralph1989, Jun 24, 2015.

  1. Ralph1989

    Ralph1989

    Joined:
    Sep 1, 2013
    Posts:
    13
    I am creating a networked version from our game. That is all going well i converted several scripts to a Networkbehavior what requires them to have a network Identity. The problem what i fase is that it is working well when i set up an connection but when i decide to play the game in offline mode (normal) the objects that are already active in the game scene are getting disabled at start. The network Identity seems todo this.

    Is this a bug or is it supposed to be like this? If so what should i do then create 2 scripts of each? I think thats abit strange todo as the Networkbehavior just overrides the monobehavior.

    When the objects get instantiate with a network idendity while not working it works fine. So what i could do is Instantiate several objects when the game starts to make sure it works while playing offline. When i have a connection it does not disable the gameobjects.
     
    MilenaRocha and macagu like this.
  2. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
  3. Ralph1989

    Ralph1989

    Joined:
    Sep 1, 2013
    Posts:
    13
  4. GixG17

    GixG17

    Joined:
    Aug 18, 2013
    Posts:
    105
    I'm not sure how to work around that considering my disabled gameObject is THE gameObject that handles most of the scripts that are used for both single-player and multi-player. It's also the script that has the menu GUI which allows a connection in the first place.

    What's really strange is that if you put a "Network Manager HUD" component, it still disables the gameObject so you can't access the buttons to start a connection.

    If it's deactivated at runtime, I'm getting a lot of errors because the various scripts don't Start() properly.

    Any help/suggestions would be appreciated
     
    Last edited: Jul 11, 2015
  5. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Put the network manager on a gameobject without networkidentity. You don't need it for that.
     
  6. bitbiome_llc

    bitbiome_llc

    Joined:
    Aug 3, 2015
    Posts:
    58
    How do you activate scene networkidentity objects on a client? The objects in question are in the scene and not added at run time. On the server I have to call NetworkServer.SpawnObjects() to activate the objects. However, on the client I cannot get them to activate. The Network Manager prefab IS instantiated at run time.

    I'm wonder if my issue is related to scene differences between the client and the host.

    NetworkManager
    • Online scene is a loading / connecting scene. Once a host has chosen what to do with the connecting player that incoming players client changes to the scene that the host is at.

    Here is the sequence of events
    1. NetworkManager Client Connect
    2. Client waits at loading /connecting scene
    3. Host assigns client to party slot
    4. Client scene changes to match host
    5. Scene based networkidentity objects never become active on the client
    I have the same issue on the host but I can call NetworkServer.SpawnObjects() and those scene based objects become active. I have tried using an rpc to have the host call NetworkServer.SpawnObjects() but that still won't activate the client inactive scene networkidentity objects.

    Is changing the scene breaking something?

    [EDIT]

    Found the answer thanks to Iron-Warrior.

    Before loading a scene on a client you must set that client to not ready, then load the scene, then on some object within that scene set the client back to ready. The ready commands must be done on the server so you will need to either issue a command by a remote object or register some network message handlers.

    Code (CSharp):
    1. void Blarg() {
    2.  
    3. //Tell server to set this player as not ready before loading a scene
    4. NetworkMasterClient.player.CmdClientReadyToggle(NetworkMasterClient.ConnectionId(),false);
    5.  
    6. //now load the scene
    7. UnityEngine.SceneManagement.SceneManager.LoadScene(msg.sceneToLoad);
    8. }
    9.  
    10.  
    11. [Command]
    12.     public void CmdClientReadyToggle(int connectionID, bool setReady) {
    13.  
    14.         //toggle ready state of a client
    15.         if( setReady )
    16.             NetworkServer.SetClientReady( NetworkServer.connections[connectionID] );
    17.         else
    18.             NetworkServer.SetClientNotReady( NetworkServer.connections[connectionID] );
    19.     }
    20.  
    21. void Start() {
    22.  
    23. //tell server that this client should be ready now
    24.         NetworkMasterClient.player.CmdClientReadyToggle(NetworkMasterClient.ConnectionId(),true);
    25. }
    26.  
    27.  
     
    Last edited: Feb 5, 2016
    Artaani likes this.
  7. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    I am loading an additive scene using this code

    Code (CSharp):
    1.  
    2. [ClientRpc]
    3.     public void RpcLoadLevelAcrossNetwork() {
    4.         //NetworkServer.SetClientNotReady()
    5.         SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
    6.      
    7.     }
    8.  
    and getting the same error that all network objects are deactive. So i found UNetSceneObjects it state that :
    but the problem is it not activating the object although its said that NetworkManager will do this automatically.(I don't know why what I am missing?)

    Then I tried NetworkServer.SpawnObjects() i call it through my code in new loaded scene it is working fine but only on server and instantiating object there not client.

    Then i saw your reply, i am beginner and much confuse that how to implment your solution. I have different client so do i have too loop through all connection or else?
     
    RuFiOHHHHH likes this.
  8. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    Can you please share the solution. I am having difficutly
     
    RuFiOHHHHH likes this.
  9. elliselkins

    elliselkins

    Joined:
    Mar 14, 2014
    Posts:
    6
    I saw a problem with objects not being activated on startup on the client that had network identities. We found that there was a child object that had a network identity, and it was deactivated. Seems that it wasn't starting properly because it was deactivated, and since child objects shouldn't have network identities (only top level objects in the scene), so it was causing networking to have problems starting up. So just remember to only have network identities on top level objects in the scene.