- Home /
How to modify enemy players meshs with Photon Unity Networking?
Hi, I'm working on streaming live data from a PC to other devices so they can observe but not modify. The PC streams the motion data to the other devices fine. What I need next is to be able to turn on and off meshes on my streaming PC character at the mobile device side without changing the original.
The only thing I want the observer device to be able to do is to change whether the main mesh or secondary mesh is visible.
Any suggestions on how to go about this? So far I thought I could stream the 2 game objects or their transforms in the OnPhotonSerializeView and then make the changes locally but this seems to prevent Unity from being able to run at all. Could I pass a boolean of Mesh.enabled or mesh.visible and make changes with that to the observer? Any and all suggestions would be welcome.
You can enable or disable the $$anonymous$$eshRenderer component of the mesh and send this state across the network, so that a single mesh will or won't be visible. Within your OnPhotonSerializeView(...) function call something like stream.SendNext(GetComponent<$$anonymous$$eshRenderer>().enabled);
when you write data to the stream and something like GetComponent<$$anonymous$$eshRenderer>().enabled = (bool) stream.ReceiveNext();
when you read from the stream.
Thanks for replying. I'll give that a go now and post back
I have also read your post on the official forums where - in my opinion - you gave some more details on what you want to achieve. Please correct me if I understood something wrong ;)
First case: PC user wants to activate/deactivate one of the meshes (the renderer) on the clients but not for his own view. This can be achieved with the help of my previous answer, but this time do not use GetComponent<$$anonymous$$eshRenderer>().enabled
when writing to the stream since this may stay enabled on the PC, but some other local variables which you can send across the network. When reading from the stream still use GetComponent<$$anonymous$$eshRenderer>().enabled = newValue
.
Second case: $$anonymous$$obile user decides if he accepts the view the PC user is trying to give him. Therefore it is best to have additional check variables for them. $$anonymous$$eans that if there is an inco$$anonymous$$g stream (because the PC user changed something) it is first checked if the mobile user wants to accept the view.
Within your OnPhotonSerializeView(...) function this might be somehing like:
if (stream.isReading)
{
if (lockView)
{
return;
}
else
{
// Update meshes according to the input stream
}
}
I reckon first case is a lot closer yea. Although the PC does the strea$$anonymous$$g I'm trying to have it so that either the PC or any observer can toggle whether the body or muscles are visible independently of the other devices. Any time the button is pressed it will only enable/disable the mesh on the device that hit the button.
The first method with "GetComponent().enabled" seemed to cause issue. I'll try creating a new bool value to save the actual value and apply it after it's been passed.