VR collider show/hide text

I am revisiting an old project, and going to try updating it, and what I had working back then, no longer works in the latest Unity (2022)

Basically, it is a VR application, and when you enter a collider area, some text fades in, stays visible, until you leave the area (collider) - rinse/repeat.

Back then, I used textmesh pro and the player rig had a collider/rigid body on, and I used this script:

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class fadeText : MonoBehaviour {

    [SerializeField]
    string displayTextForThisCollider;

    void OnTriggerEnter (Collider col)
    {
        if (col.gameObject.name == "Player") {
            DOTween.PlayForward (displayTextForThisCollider);
            Debug.Log ("entered");
        }
    }

    void OnTriggerExit(Collider other)
    {
        DOTween.PlayBackwards(displayTextForThisCollider);
    }
}

The collider has the above script attached to it.
The text was canvas, with a child of textmesh pro and dotween.

Ive since upgraded the VR rig to use hurricane VR, and Ive attached a child collider to it. (so it interacts with the other colliders to trigger the fade in.

Everything seems to be configured as how I used to have it, except it doesn’t work - when I test the game, the text is not visible (good), when I go into the collider, nothing happens… I’m not even seeing the debug log displayed in the console.

So, is there an easier method to do this these days? Or do you see some issue with the above?, I just need to figure out why its not triggering. (yes, collider is trigger) I have a lot of text in different areas and I don’t want them all displayed at once.

Thanks

Start finding out what it’s actually doing first, otherwise you won’t know how to fix it.’

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: How To - Capturing Device Logs on iOS or this answer for Android: How To - Capturing Device Logs on Android

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

You must find a way to get the information you need in order to reason about what the problem is.