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.
sending a game object name through custom messages in Sharing of holograms
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
PS: sorry for the improper editing of code
Best Answer
-
Sachin ✭
I have tried the same and got success by simply sending the GameObject name and receive it.. I have check your code and you are doing a simple mistake in "OnGameObjIdRcv" method. You have to read a name from msg object like following:
void OnGameObjIdRcv(NetworkInMessage msg) { msg.ReadInt64(); string objname_in_msg = msg.ReadString(); temp = GameObject.Find(objname_in_msg); temp.SendMessageUpwards("SpawnObjforAllClients"); }
You can also send more then one object name in single Message.
8
Answers
I have tried the same and got success by simply sending the GameObject name and receive it.. I have check your code and you are doing a simple mistake in "OnGameObjIdRcv" method. You have to read a name from msg object like following:
You can also send more then one object name in single Message.
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!