Hello everyone.

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.

Share an object and let every user move it

Greetings,

I need to acomplish this task that seems to be simple but I can't find the proper way to achieve it : I want to be able to move a cube (for now) and everyonne else connected to the shared experience can see it and move it too, with a HandDraggable or a TapToPlace for instance. I made a panel with buttons so the user can translate the cube and I thought it may be easier to trigger actions based on buttons.

Here is what I currently managed to do :

  • configure a server running ServiceManager.exe
  • connect 2 hololens to the server
  • they both see the cube on the same spot.

I've been through Holograms 240, watched all the videos and tried to understand the code, I read through CustomMessages.cs, HologramPlacement.cs and RemotePlayerManager.cs trying to figure it out but I'm lost, I don't know which lines are needed and which aren't. I understand that the position needs to go through CustomMessages.cs in order to be broadcasted but I don't know what exactly I have to add in the script and if I have to add something elsewhere.
My programming skills are limited and I don't grasp every concept in those files. I just need to share the cube's location and let everyone move it. I know there would be a conflict if several people are trying to move it with a HandDraggable/TapToPlace but I don't care, let's say I'll take the last location where the cube has been placed.

Any help would be appreciated.

Tagged:

Best Answer

Answers

  • Thanks for the link, this thread was very helpful. I tried to follow the steps explained by @bharat1995 and also applied the correction from @Sachin however I can't make it work.

    I tried to keep it very simple: whenever I click on a button, it shares how many times this button has been clicked and when another hololens receives it, it displays this number in a textbox.

    Here is my code:

    • For sending the message:

    **This script is called whenever I click on the button **:

    public class ButtonSend : MonoBehaviour {
    
    int i = 0;
    public GameObject myButton;
    
    public void SendClick()
    {
        i++;
        CustomMessages.Instance.SendButtonClick(i.ToString());
    }
    

    }

    The scripts I added in CustomMessages:

        public void SendButtonClick(string i)
        {
            // If we are connected to a session, broadcast our head info
            if (serverConnection != null && serverConnection.IsConnected())
            {
                // Create an outgoing network message to contain all the info we want to send
                NetworkOutMessage msg = CreateMessage((byte)TestMessageID.Clicked);
            // I added the value "Clicked" on the ThestMessageID enum but I'm not sure if it's helping.
                AddButtonClick(msg, i);
    
                // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
                serverConnection.Broadcast(
                    msg,
                    MessagePriority.Immediate,
                    MessageReliability.UnreliableSequenced,
                    MessageChannel.Avatar);
            }
        }
    

    and

        void AddButtonClick(NetworkOutMessage msg, string i)
        {
            msg.Write(i);
        }
    
    • Now when receiving:

      public GameObject ButtonReceiving; //Yes it's a button, I'll just get the text component in his Text child.

      void Start () {
      CustomMessages.Instance.MessageHandlers[CustomMessages.TestMessageID.Clicked] = OnMessageReceived;
      }

      void OnMessageReceived(NetworkInMessage msg)
      {
      msg.ReadInt64();
      string i = msg.ReadString();
      ButtonReceiving.GetComponentInChildren().text = i;
      }
      }

    And nothing happens. I also added some sort of debug where it would write something in a textbox if the script OnMessageReceived was called but it never writes anything.
    I would also add that the head sharing works well, a box appears on the location of the other HoloLens.

    Any help would be appreciated, at this point I don't know what to try else.

  • Thanks for the link, this thread was very helpful. I tried to follow the steps explained by @bharat1995 and also applied the correction from @Sachin however I can't make it work.

    I tried to keep it very simple: whenever I click on a button, it shares how many times this button has been clicked and when another hololens receives it, it displays this number in a textbox.

    Here is my code:

    For sending the message:

    This script is called whenever I click on the button:

    public class ButtonSend : MonoBehaviour {
    
    int i = 0;
    public GameObject myButton;
    
    public void SendClick()
    {
     i++;
     CustomMessages.Instance.SendButtonClick(i.ToString());
    }
    
    }
    

    The scripts I added in CustomMessages:

    public void SendButtonClick(string i)
    {
        // If we are connected to a session, broadcast our head info
        if (serverConnection != null && serverConnection.IsConnected())
        {
            // Create an outgoing network message to contain all the info we want to send
            NetworkOutMessage msg = CreateMessage((byte)TestMessageID.Clicked);
        // I added the value "Clicked" on the ThestMessageID enum but I'm not sure if it's helping.
            AddButtonClick(msg, i);
    
            // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
            serverConnection.Broadcast(
                msg,
                MessagePriority.Immediate,
                MessageReliability.UnreliableSequenced,
                MessageChannel.Avatar);
        }
    }
    

    and

    void AddButtonClick(NetworkOutMessage msg, string i)
    {
        msg.Write(i);
    }
    

    Now when receiving:

    public GameObject ButtonReceiving; //Yes it's a button, I'll just get the text component in his Text child.
    
    void Start () {
          CustomMessages.Instance.MessageHandlers[CustomMessages.TestMessageID.Clicked] = OnMessageReceived;
      }
    
      void OnMessageReceived(NetworkInMessage msg)
      {
       msg.ReadInt64();
       string i = msg.ReadString();
       ButtonReceiving.GetComponentInChildren<Text>().text = i;
      }
    
      }
    

    And nothing happens. I also added some sort of debug where it would write something in a textbox if the script OnMessageReceived was called but it never writes anything.
    I would also add that the head sharing works well, a box appears on the location of the other HoloLens.

    Any help would be appreciated, at this point I don't know what to try else.

  • I'll try this when I go back to work tuesday. Indeed I just wrote it like this:

    public enum TestMessageID : byte
    {
    Clicked
    Max
    }
    

    I didn't know that MessageID.UserMessageIDStart was needed, because actually I don't fully inderstand this line and what it's used for.
    I'll let you know how it goes, thank you.

  • @Adurnat said:
    I didn't know that MessageID.UserMessageIDStart was needed, because actually I don't fully inderstand this line and what it's used for.

    While we are using custom messages, there are also internal message being passed around. These messages also have IDs, which you can find in MessageID.cs. You can see that MessageID.UserMessageIDStart is set to Start+50, so that user (custom) messages do not have conflicting IDs with internal messages.

  • @mark_grossnickle Adding this line worked, thank your very much ! Although I have one last question concerning this line:
    Since there was already HeadTransform = MessageID.UserMessageIDStart,
    I wrote Clicked = MessageID.UserMessageIDStart + 1,
    Is this the proper way to do it ?

  • I don't think you need the plus one on the Clicked. Just the HeadTransform one should have the UserMessageIDStart. Enums should increment automatically after the first one.

    Taqtile

  • Ok wonderful, thanks again it really helped a lot !

Sign In or Register to comment.