Making Triggered Text Appear in VR: An Adventure

James Murphy
RE: Write
Published in
5 min readFeb 12, 2018

This is one of those problems that was an adventure to solve. I am developing a maze in virtual reality. I built the maze using the terrain feature so it is like navigating a maze made of hills or mountains rather than walls or hedges. I used colored point lights to create a color map. The bluer the color the closer you are to the exit.

As the player makes their way through the maze they will get text prompts telling them hot or cold depending how close they are from the exit. Getting these text prompts to show in Virtual Reality took me annoyingly forever to do.

I started by creating the text components. Creating a new UI Text created the canvas for it to be on. The canvas is where all UI elements for the game or experience go. So all of my messages would live on the same canvas. This got a little confusing with six distinct messages.

I could not have all of these showing at once all the time. I wanted a certain message to display only when the player was at a certain part of the maze. This would be done with trigger objects, one per message. I created an empty game object, checked ‘is trigger’, duplicated it, and moved the duplicates to different parts of the map.

Now that my trigger objects and my messages were created, I needed a script to connect the two.

This amazing tutorial on YouTube: Unity 5 — Showing Text on Trigger helped me build the perfect script. I was able to apply it to each trigger object and move the right message into the UI Object field and it was time to test.

I had been using a small prebuilt character I named Kevin from the asset store to test my maze. I just made sure that Kevin was tagged “Player”.

I walked him through and boom! It worked.

Next step would be to apply this to VR. To do this I was using another free package from the asset store called VRTK — Virtual Reality Toolkit.

They had a large variety of examples and some of those examples were movement. I chose a simple one that wasn’t too demanding of the player, TouchPadWalking.

I copied and pasted the needed parts from their scene into my own.

I now had a working VR Camera Rig I could use with the HTC Vive. Any scripts or settings that were applied to Kevin now had to be applied to the Camera Rig. Just needed to change the tag.

Yet when I went into VR and tested, it failed. Every single time. The screen would go blank as I passed through the trigger object, but no message.

I went over everything and could find nothing wrong. I googled and googled and started to venture deeper into how to interact in VR. Nothing.

I knew the script was working so it had to be something with rendering the text in VR so the player could see the message.

I tried remaking my messages as 3D Text instead of using the UI Text Element. 3D text could be placed anywhere in the game space but this was not the solution either. I got the same result. I would run through the trigger in VR and no text would appear. I went back to using UI Text with my messages spread all over the canvas.

It wasn’t until I was messing with settings on the canvas itself that I was finally able to solve the problem. A single setting that was responsible for hours of problem solving. Changing the Canvas Render Mode from Screenspace — Overlay to Screenspace — Camera. This put the canvas in front of the VR camera rig.

Now when I hopped in VR it was a success! As I ran through the maze the corresponding messages popped up. Just as planned.

--

--

James Murphy
RE: Write

From Flint, MI where I was a marketing project manager for Kettering University. Came to Boulder for grad school and adventure. Passions: Pets, Tech, Nature.