Search Unity

Does "Find" Still Work For Multiplayer?

Discussion in 'Scripting' started by DRRosen3, Dec 19, 2014.

  1. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    I've always wondered this. If you build a multiplayer game, does using commands like "FindGameObjectWithTag" or "FindGameObject" conflict between clients/players? For example...HUD's... If I wanted to access a player's HUD via script and I used "FindGameObjectWithTag("HUD")...would that not work because every player online has a HUD, or will it only find the HUD of the player of the game being run on that specific device?
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Hopefully the client is only displaying/storing a single HUD, so it shouldn't have any conflicts. Those functions don't traverse across the network; they only see what is in the current scene.

    If you have duplicated HUDs in the hierarchy for every player, you're doing something wrong.
     
    image28 likes this.
  3. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    For a HUD you would only have one HUD for the local player. If for some reason you had multiple huds for each player all running localy, you would have to store them in an array, or find them based on name and change the name of each one to the correct player ID....e.g Player1Hud, Player2Hud, etc...
     
  4. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    you beat me to it by a minute....
     
  5. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Well, I'm just trying to get my mind wrapped around (online) multiplayer concepts before I start getting my hands dirty. Each player/client would only have one HUD...I just wanted to make sure the call to find the HUD would stay local, and wouldn't find other HUDs in the same scene/level, which @DanielQuick answered...I think...by saying that functions like that don't cross the network.