Search Unity

"isServer" is false when called from NetworkManager!

Discussion in 'Multiplayer' started by UnbreakableOne, Oct 21, 2015.

  1. UnbreakableOne

    UnbreakableOne

    Joined:
    Nov 16, 2013
    Posts:
    168
    Hi,

    In my NetworkManager derived class, I instantiate my player (which is a NetworkBehaviour) and thus calls it's Awake() and in that Awake() call I check for isServer but it is false! Why is that?

    I mean the call is initiated from server obviously, am I right?

    I even put [ServerCallback] attribute before Awake() but the isServer is still false!
     
  2. SpeakUpGames

    SpeakUpGames

    Joined:
    Nov 25, 2014
    Posts:
    56
    From Network Overview:
    • isServer - true if the object is on a server (or host) and has been spawned.
    • isClient - true if the object is on a client, and was created by the server.
    • isLocalPlayer - true if the object is a player object for this client.
    • isAuthority - true if the object is owned by the local process
    Has the player object been spawned?
     
    MsMaciek likes this.
  3. UnbreakableOne

    UnbreakableOne

    Joined:
    Nov 16, 2013
    Posts:
    168
    My object is getting instantiated and spawned on the server.
     
  4. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    @UnbreakableOne
    That's because some of the NetworkBehaviour initialization happens after the MonoBehaviour's Awake phase.

    I've noticed almost all needed stuff is properly initialized at the Start() phase, but didn't checked it outside LAN network or with emulated latency.

    NetworkBehaviour has buch of own callbacks you may use to perform network-specific actions (like OnStartLocalPlayer, etc.)
     
    kaleidosgu and lexi89puzzle like this.
  5. kaleidosgu

    kaleidosgu

    Joined:
    Jan 8, 2017
    Posts:
    5
    Dmitriy-Yukhanov is right. And thank Dmitriy and this post
    I met a problem. When I wrote a function in ondestroy(), I found isserver is false. But this prefab is spawn on the server actually.
    Then I read the network codes. Isserver is going to be false when the object be destroied. Because my component is behind the Networkidentity. And Isserver is from networkidentity's variable. That's the reason why isserver is false
     
  6. Zythus

    Zythus

    Joined:
    Jun 28, 2014
    Posts:
    30
    Is there an easy way to call the host, and the client connected to the host that hosts the server? Since as far as I know calling isServer doesn't give you the host...