Search Unity

Question OnTriggerExit doesn't work on the host.

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

  1. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    i have a very simple code that looks like this
    Code (CSharp):
    1.    
    2.     private void OnTriggerExit(Collider other)
    3.     {
    4.         other.gameObject.SetActive(false);
    5.         GameObject.Find("GameController").GetComponent<GameController>().playersalive.Remove(other.gameObject);
    6.     }
    7.  
    the problem is that the gameobject doen't get deactivated on the host, altho every player has the gameobject and the collider that this script is attached to.
     
  2. pixaware_pwedrowski

    pixaware_pwedrowski

    Joined:
    Oct 25, 2018
    Posts:
    116
    Trigger events are only sent if one of the Colliders also has a Rigidbody attached - do you have a Rigidbody component attached to your players?
     
  3. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    yes
     
  4. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    i fixed it, i think that the issue was that another script tried to use that gameobject so it wasn't able to get turned off. or at least i think so