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.

sending a game object name through custom messages in Sharing of holograms

edited December 2016 in Questions And Answers

Hi,
I am working on a code where i want to pass the name of the game object via custom messages and send it to all other users in the sharing service so that they can spawn the game object. The code goes as follows:

For sending the message:
script 1 :
CustomMessages.Instance.SendGameObj(this.gameObject);

custom messages:

public void SendGameObj(GameObject obj)
            {
                // If we are connected to a session, broadcast our head info
                if (this.serverConnection != null && this.serverConnection.IsConnected())
                {
                    // Create an outgoing network message to contain all the info we want to send
                    NetworkOutMessage msg = CreateMessage((byte)TestMessageID.clicked);

                    //Appending a gameobj to the message
                    AddGameObj(msg, obj);

                    // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
                    this.serverConnection.Broadcast(
                        msg,
                        MessagePriority.Immediate,
                        MessageReliability.ReliableOrdered,
                        MessageChannel.Avatar);
                }
            }

**and **

void AddGameObj(NetworkOutMessage msg, GameObject obj)
    {
        //msg.Write(obj.GetInstanceID());
        msg.Write(obj.name);
       // Debug.Log(obj.name);
    }

I assume this should write the message in and send it to all users

**Now while receiving :
In another script's start method : **

 CustomMessages.Instance.MessageHandlers[CustomMessages.TestMessageID.clicked] = this.OnGameObjIdRcv;

and the method :

 void OnGameObjIdRcv(NetworkInMessage msg)
    {
        msg.ReadInt64();

        temp = GameObject.Find(CustomMessages.Instance.ReadGameObjName(msg));
        temp.SendMessageUpwards("SpawnObjforAllClients");
    }

**and the method which spawns the game object : **

 void SpawnObjforAllClients()
    {
        spawnPosition = GameObject.Find("Catalogue").transform.position;
        spawnPosition.y -= yComponent;
        spawnPosition.z -= 0.35f;

        i = 0;
        //Debug.Log (spawnObjects[0].name);
        foreach (GameObject spawnObject in spawnObjects)
        {

            refObjects[i] = ((GameObject)Instantiate(spawnObject, spawnPosition, Quaternion.identity));

            refObjects[i].GetComponent<Rigidbody>().isKinematic = true;
            Collider[] colliders = refObjects[i].GetComponentsInChildren<Collider>();

            /// to make the spawned gameobj, face the user..
            Quaternion toQuat = Camera.main.transform.localRotation;
            toQuat.x = 0;
            toQuat.z = 0;
            refObjects[i].transform.rotation = toQuat;


            i = i + 1;
        }

the receiver is not at all able to automatically spawn the game object ......

Can any one help me with this ..Thnx :smile:

PS: sorry for the improper editing of code :persevere:

Tagged:

Best Answer

Answers

  • Hi,

    I'm trying to add a button in my HoloLens app which would send a message to my Desktop/PC app to launch an application on my Desktop. Could you please briefly explain what are the steps to be followed in order to achieve this using CustomMessages.

    Regards,
    Pranav

  • Thank you both so much! You helped me unbelievably much!

Sign In or Register to comment.