Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

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.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. 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. And always feel free to hit us up on Twitter @MxdRealityDev.

How do you get position of the controller of with unity?

I have been using the interaction manager to connect the controllers (which are tricky as it appears I have to push windows button, go to mixed reality portal and then back to unity for it to connect, any clues how to make it connect are appreciated) and it doesn't seem to matter what I have the SourcePos never returns a position.

Can anyone get this work and if so what is the trick?

Script below

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.WSA.Input;

public class ControllerInput : MonoBehaviour {

// Use this for initialization
void Start () {

    InteractionManager.InteractionSourceDetected += InteractionManager_SourceDetected;
    InteractionManager.InteractionSourceUpdated += InteractionManager_SourceUpdated;
    InteractionManager.InteractionSourceLost += InteractionManager_SourceLost;
    InteractionManager.InteractionSourcePressed += InteractionManager_SourcePressed;
    InteractionManager.InteractionSourceReleased += InteractionManager_SourceReleased;
}

void OnDestroy()
{

    InteractionManager.InteractionSourceDetected -= InteractionManager_SourceDetected;
    InteractionManager.InteractionSourceUpdated -= InteractionManager_SourceUpdated;
    InteractionManager.InteractionSourceLost -= InteractionManager_SourceLost;
    InteractionManager.InteractionSourcePressed -= InteractionManager_SourcePressed;
    InteractionManager.InteractionSourceReleased -= InteractionManager_SourceReleased;
}
    // Update is called once per frame
void Update ()
{
    //Vector3 leftPosition = InputTracking.GetLocalPosition(XRNode.LeftHand);

    //Debug.Log("LP" + leftPosition);


    var interactionSourceStates = InteractionManager.GetCurrentReading();
    Debug.Log("Num Interaction Source States: " + interactionSourceStates.Length);
    /*
    if (interactionSourceStates.selectPressed)
    {
        Debug.Log("Press" + Time.time);
    }
    */
    if (Input.GetButton("Fire1"))
    {
        Debug.Log("Fire1");
    }

}

void InteractionManager_SourcePressed(InteractionSourcePressedEventArgs args)
{

    Debug.Log("Source pressed");
}
void InteractionManager_SourceDetected(InteractionSourceDetectedEventArgs args)
{

    Debug.Log("Source detected");
}
void InteractionManager_SourceUpdated(InteractionSourceUpdatedEventArgs args)
{
    Vector3 p;
    //float a;
    args.state.sourcePose.TryGetPosition(out p);
    //a = args.state.sourcePose.positionAccuracy;

    //Debug.Log("Source updated " + p);
}
void InteractionManager_SourceLost(InteractionSourceLostEventArgs args)
{

    Debug.Log("Source lost");
}
void InteractionManager_SourceReleased(InteractionSourceReleasedEventArgs args)
{

    Debug.Log("Source released");
}

}

Answers

  • I'm also having this issue just in the MotionControllerTest scene in the MRTK

  • I am using the standard unity build

  • I find that I need to close the mixed reality portal every time before launching from unity for the controllers to work.

Sign In or Register to comment.