- Home /
Question by
terabix · Aug 12, 2018 at 09:15 AM ·
multiplayermultiplayer-networking
Code works on host but not on client
I have multiplayer networking code that works on host but not on client. On client FindObjectOfType fails to retrieve the BoardManager. However, it might be happening with the others as I encountered a similar error before. Can anyone explain why Unity can only retrieve an object once and how to get my code working?
//Function of GameManager
void Start() {
playerCount = 0;
net_manager = FindObjectOfType<NetworkManager>();
board_manager = FindObjectOfType<BoardManager>();
terrain_manager = FindObjectOfType<TerrainManager>();
selection_manager = FindObjectOfType<SelectionManager>();
unit_build_menu_manager = FindObjectOfType<UnitBuildMenuManager>();
terrain_info_panel_controller = FindObjectOfType<TerrainInfoPanelController>();
unit_info_panel_controller = FindObjectOfType<UnitInfoPanelController>();
terrain_manager.InitializeManagers(this, board_manager);
board_manager.InitializeManagers(this, terrain_manager);
selection_manager.InitializeManagers(terrain_manager, board_manager, terrain_info_panel_controller, unit_info_panel_controller);
unit_build_menu_manager.InitializeManagers(this, selection_manager, board_manager);
terrain_manager.FetchMapData();
max_players = terrain_manager.GetMaxPlayers();
playerList = new ArrayList();
currentTurn = 0;
}
//Function of BuildingController
public void InitiateManagers(GameManager game_manager, BoardManager board_manager)
{
this.game_manager = game_manager;
this.board_manager = board_manager;
Debug.Log(board_manager); //returns null
board_manager.RegisterBuilding(this.gameObject); //throws an exception
}
Comment
The only reason this would fail because in the client there is no Board$$anonymous$$anager object. Perhaps it is destroyed on a scene switch? Or was it never Instantiated on the client?
Best Answer
Answer by terabix · Aug 12, 2018 at 01:49 PM
I found the issue. You have to call NetworkServer.SpawnObjects() on the server.
Your answer