Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Turn-based Multiplayer: Storing Players in a Player System: Problem with accessing NetworkIdentity

Discussion in 'Multiplayer' started by SkollGER, Jan 21, 2016.

  1. SkollGER

    SkollGER

    Joined:
    Apr 2, 2013
    Posts:
    12
    Hey there,

    I am currently working on a turn-based game and I am struggling with the new HLAPI Networking.

    I set up a Lobby, players spawn on start positions and the color and playernumber are synced.

    Now I want to make the already implemented GameController, PlayerSystem and TileSystem work. The PlayerSystem stores a List of the Players, the current Player, handles what happens on NextTurn and if a Player is able to build or upgrade (checking for ressources of the Player). The TileSystem spawns the Tiles on runtime and handles claiming, upgrading and attacking.

    The problem you will see in the attached project when you host a game out of the NetworkLobby scene is a NullReferenceException. After adding the NetworkIdentity component to the GameController (holds GameController, TileSystem and PlayerSystem), the LobbyManager (and the Player in the Awake method) can't find the GameController with the NetworkIdentity.

    I have read http://docs.unity3d.com/Manual/class-NetworkIdentity.html :
    "Scene objects are treated a bit differently than dynamically instantiated objects. These objects are all present in the scene on both client and server. However, when building the game all the scene objects with network identities are disabled. When the client connects to the server the server tells the client which scene objects should be enabled and what their most up to date state information is through spawn messages. This ensures the client will not contain objects placed at now incorrect locations when he starts playing, or even objects which will be deleted immediately on connection because some event removed them before the client connected. The Server Only checkbox will ensure this a particular object will not be spawned or enabled on clients."

    I think there is the problem, but I don't know a way around it.

    Thank you in advance for any help!
     

    Attached Files:

  2. sdnsepehr

    sdnsepehr

    Joined:
    Oct 9, 2015
    Posts:
    7
    Hey, I am facing the same problem. I have searched a lot but did't find any help. if you found a way, please share with me. thank you
     
  3. SkollGER

    SkollGER

    Joined:
    Apr 2, 2013
    Posts:
    12
    In the end I used the free version of PUN (Photon Unity Networking).
     
  4. sdnsepehr

    sdnsepehr

    Joined:
    Oct 9, 2015
    Posts:
    7
    could you please share it with me or any tutorial?
    thank you
     
  5. SkollGER

    SkollGER

    Joined:
    Apr 2, 2013
    Posts:
    12
    Hm, I don't know anymore which tutorial I used, but the github repository is public. It was a small project for university... not bug-free though, nor has it good comments: https://github.com/Skoll85/Realms-of-Morra