The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
How to display text when selecting an object
I'm trying to build a simple app that displays text above a hologram once I gaze at and air-tap to select that hologram. Can someone help me out? I'm new to Hololens development. Currently using the Holotoolkit, but don't know how to proceed.
I have the "Tap Responder" script attached to my holograms, as well as the "Tap To Place" script (however the latter is not working). I've also included the InputManager, EventSystem, SpatialMapping and RemoteMapping prefabs in a blank object I've called "Managers".
Best Answers
-
OptionsDonPepe ✭
To get notified when you're gazing at an object, you can use the GazeManager from the HoloToolkit. Also the GestureManager is using it to determin at which object you're gazing when you do a tap. Just place them both on an empty Managers object like you did.
When you check the GestureManagers code you'll find the Method OnTap() at around line 135. That's where it sends a message to the tapped object. So all you need to do is, to have a function (with the name whatever it is in the sendmessage parameter) on the target object and that function will get called when you tap the object. Make sure you're having a collider on the object. Otherwise it won't work.6 -
Optionskeljed ✭✭
- Use an InputManager and a Cursor
- Create a prefab for your text (maybe based on HoloToolkit UITextPrefab)
- create and attach a script that implements IInputClickHandler to your hologram/gameobject
- Associate your text prefab with the script
- instantiate your prefab and place it above your gameobject on click event
`
public class ShowOnTap : MonoBehaviour, IInputClickHandler
{
public GameObject TextPrefab;public void OnInputClicked(InputEventData eventData) { var text = Instantiate(TextPrefab); var position = gameObject.transform.position; text.gameObject.transform.position = new Vector3(position.x, position.y + 0.1f, position.z); } }
`
5 -
Optionskeljed ✭✭
There is a prefab called "UITextPrefab" in the HoloToolkit. You can create a new prefab with your own text based on it. I think I can remember that I had to set a font before my text was visible, because it was not set on the HoloToolkit prefab.
In the editor you can drag your prefab on the TextPrefab property of the "ShowOnTap" script component of your game object.
A new instance of the prefab will be created and added to the scene when you tap the gameobject.From the question where to place the prefab I assume your not familiar with prefabs. So have a look here, first:
https://docs.unity3d.com/Manual/Prefabs.html
You could also pre-place a hidden text object in the scene and just make it visible on tap.
5
Answers
To get notified when you're gazing at an object, you can use the GazeManager from the HoloToolkit. Also the GestureManager is using it to determin at which object you're gazing when you do a tap. Just place them both on an empty Managers object like you did.
When you check the GestureManagers code you'll find the Method OnTap() at around line 135. That's where it sends a message to the tapped object. So all you need to do is, to have a function (with the name whatever it is in the sendmessage parameter) on the target object and that function will get called when you tap the object. Make sure you're having a collider on the object. Otherwise it won't work.
`
public class ShowOnTap : MonoBehaviour, IInputClickHandler
{
public GameObject TextPrefab;
`
@keljed Where do I place the UITextPreFab - In the hierarchy, or as a child of my hologram? If the prefab is called UITextPrefab, do i need to call it that specifically in the code above?
There is a prefab called "UITextPrefab" in the HoloToolkit. You can create a new prefab with your own text based on it. I think I can remember that I had to set a font before my text was visible, because it was not set on the HoloToolkit prefab.
In the editor you can drag your prefab on the TextPrefab property of the "ShowOnTap" script component of your game object.
A new instance of the prefab will be created and added to the scene when you tap the gameobject.
From the question where to place the prefab I assume your not familiar with prefabs. So have a look here, first:
https://docs.unity3d.com/Manual/Prefabs.html
You could also pre-place a hidden text object in the scene and just make it visible on tap.
Hi, I had the same question and I realized that you can query the object "under" the Gaze like this:
Hi sgambolati,
I also want to check the name of the gazed object like you suggested, but I got a null reference exception.
In my scene I have a manager gameobject with all the manager scripts (e.g. gaze, gesture,...). Additionally I introduced another gameobject "VoiceManager", which shows a text when a specific object is gazed.
When I run the program, I got a NullReferenceException, but I "wired" the text and the RawImage.
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity.InputModule;
using UnityEngine.UI;
public class VoiceManager_Main : MonoBehaviour {
}
Hi @ChristophMarko , it is probably because you are trying to get the HitObject.name but that might be null. I wouldn't go in this direction unless you really have to. Instead, if you want to "Do Something" to an object you are looking at then, you should attach a script to that object and inherit from the IFocusable script. Whenever you look at the object, the OnFocusEnter will be called.
AR Developer
Hi @dbarrett, thank you for your reply and your information. My intention was to compare the name of the gazed object with the name of a button. When the right button was gazed a text will be shown, other wise nothing will be shown.
In my scene I have 3 buttons and the funny thing is that it doesn't work with the first button but for the other 2 buttons it worked quite good.
It the simplest way, and I've not read the above ... there is a raycast that is performed, and when the object is aligned with the ray ... the one your eyes define ... then the object has an event sent to it ... and can respond ... for instance by lighting up some specific text ... in your event handler for that object.
This is down into the details ... if you're up at the toolbox level.
Signed, a monkey minded simpleton ... just a fool ... don't read posts by Utekai either ... I mean likely you can't most are hidden.