Search Unity

Question Clients can't interact with the hud

Discussion in 'Netcode for GameObjects' started by KristenBoyGames, May 15, 2022.

  1. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    The clients can't interact with the hud, they see the hud but when you hover over or click the buttons on the screen the game doesn't detect it. What could be causing it?
     
  2. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    Can you post all your relevant code?
     
  3. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using TMPro;
    5. public class PlayAreaUiManager : MonoBehaviour
    6. {
    7.     public GameObject PlayAreaMenu;
    8.     public GameObject AllwaysOnScreenMenu;
    9.  
    10.     private void Start()
    11.     {
    12.         PlayAreaMenu.SetActive(false);
    13.         AllwaysOnScreenMenu.SetActive(true);
    14.     }
    15.     public void openPlayAreaMenu()
    16.     {
    17.         PlayAreaMenu.SetActive(true);
    18.         AllwaysOnScreenMenu.SetActive(false);
    19.         Debug.Log("openedGameAreaMenu");
    20.     }
    21.     public void closePlayAreaMenu()
    22.     {
    23.         PlayAreaMenu.SetActive(false);
    24.         AllwaysOnScreenMenu.SetActive(true);
    25.     }
    26.  
    27. }
    28.  
    this is all the code.
     
  4. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    The code is simple enough, the functions
    openPlayAreaMenu
    and
    closePlayAreaMenu
    are connected to buttons on the UI I assume? Have you checked that this is still true in the Inspector when the editor is running a client instance? Is the
    PlayAreaUiManager
    on an object that exists for the client?
     
  5. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    yes the functions are connected to buttons on the ui, the script is on the GameController and that is active for clients, the problem seems to be that the system that tells the game when you are hovering over a button is not working, i set the highlighted color to red and the buttons don't change when i hover over them. i don't see any differences between the host and the client in the editor.
    EDIT: that seems to be the case, i put the open and close functions to keys on my keyboard and now they work.
     
    Last edited: May 17, 2022
  6. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    ok so i did some testing and the issue is in the netcode, i joined as client (the hud didnt work), stopped the client (the hud didn't work), started host (the hud worked). And i did this via the networkManager object without leaving the scene so there is no way that the code had loaded something different with the client. so the thing is that for the raycast or whatever is responsible for the detection of the cursor to work you need to be host, why and where to change it.

    Are there any components that are needed on the hud objects to work like this or what?