# Simple trigger issue

**URL:** https://discussions.unity.com/t/simple-trigger-issue/841361
**Category:** Scripting
**Tags:** Scripting
**Created:** [May 18, 2021, 11:26pm UTC](https://discussions.unity.com/t/simple-trigger-issue/841361 "2021-05-18T23:26:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![TravisKTP](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/travisktp/32/486150_2.png) [@TravisKTP](https://discussions.unity.com/u/TravisKTP)
#### Post date: [May 18, 2021, 11:26pm UTC](https://discussions.unity.com/t/simple-trigger-issue/841361/1 "2021-05-18T23:26:05Z")

</div>

Hey all, just having a simple trigger issue for a UI element and not sure why it is not working. I am making a square with a sphere trigger collider that, when entered, will turn a UI element on, and when exited, will turn the UI element off. However, I am having some issues. When entering the sphere trigger, the UI element turns on as needed. However, when exited, the UI element stays on screen and will not leave. Any thoughts as to why this could be happening? Code is below:

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BoxCollision : MonoBehaviour
{
    public GameObject boxDisplay;

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
           boxDisplay.SetActive(true);
        }
    }

    void OnTriggerExit(Collider other)
    {
        if(other.tag == "Player")
        {
            boxDisplay.SetActive(false);
        }
    }
}

```

---

<div class="post-metadata">

### Author: ![PutridEx](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/putridex/32/152048_2.png) [@PutridEx](https://discussions.unity.com/u/PutridEx)
#### Post date: [May 18, 2021, 11:33pm UTC](https://discussions.unity.com/t/simple-trigger-issue/841361/2 "2021-05-18T23:33:27Z")

</div>

Does OnTriggerExit inside the if statement run? Stick a debug In there and see if it shows up

---

<div class="post-metadata">

### Author: ![TravisKTP](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/travisktp/32/486150_2.png) [@TravisKTP](https://discussions.unity.com/u/TravisKTP)
#### Post date: [May 18, 2021, 11:43pm UTC](https://discussions.unity.com/t/simple-trigger-issue/841361/3 "2021-05-18T23:43:00Z")

</div>

Tested it out, and it does work, but only extremely selectively. I tried switching it out with another box collider which works slightly better. Guess its just a case of wonky detection??? However, still does not work to my liking. It isnt overly complex too, just simple models. Not sure why this is happening lol

---

<div class="post-metadata">

### Author: ![Kurt-Dekker](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kurt-dekker/32/101578_2.png) [@Kurt-Dekker](https://discussions.unity.com/u/Kurt-Dekker)
#### Post date: [May 18, 2021, 11:43pm UTC](https://discussions.unity.com/t/simple-trigger-issue/841361/4 "2021-05-18T23:43:14Z")

</div>

> [@PutridEx](#):
>
> Does OnTriggerExit inside the if statement run? Stick a debug In there and see if it shows up

I would take it even further and say make sure it runs OUTSIDE of the if statement… print the tag of the collider and see what it might be right at the top of those functions.

Also, if you put Debug.Log() calls inside each of those trigger functions, right at the top, and print the name and the tag of the collider involved, that might give some clues too.

---

<div class="post-metadata">

### Author: ![Kurt-Dekker](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kurt-dekker/32/101578_2.png) [@Kurt-Dekker](https://discussions.unity.com/u/Kurt-Dekker)
#### Post date: [May 18, 2021, 11:44pm UTC](https://discussions.unity.com/t/simple-trigger-issue/841361/5 "2021-05-18T23:44:54Z")

</div>

> [@TravisKTP](#):
>
> wonky detection???

Oh … how are you moving the object? You can NOT just assign to transform.position (and you can’t use Transform.Translate either!).

You can only move Rigidbody physics by calling the .MovePosition() method on the actual rigidbody. Otherwise yeah, you are startling the physics system and sneaking stuff around it.
