- Home /
photon transform view not syncing???
So im making a flood escape game where one player presses a button and an object disappears. Everything is working but whenever one player clicks the button, it only opens up for that player and for the rest of the players it just shows closed. I put a photon transform view and attached it to the photon view but its still not working???][1]
Answer by Captain_Pineapple · May 08, 2019 at 07:30 AM
Hey there,
a transform view will not synchronize the current active state of an object. So in case you deactivated the object this will not work. What should work is to move the object somewhere offscreen. Since the transform view updates scale translation and rotation it should move for all players.
Be careful here: If this "door" is an object that you got multiple times in your game then updating all 3 values in the network will make you reach your max message limit quite fast.
A better solution would be to give your Bob script an rpc. This rpc will have no other job than to disable your gameobject. This will save a huge huge huge amount of traffic and will actually be able to disable and not only "store away" your door.
If you need help with that let me know. Otherwise share some code how you currently solve this so that we might check for code issues.
Thanks again for helping me but I have a problem. Its not working. When I tried changing the position all it did was just go right back. Then I tried using sending the position of the object but it didn't work. If you want to check the send code here it is.`using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; public class c : $$anonymous$$onoBehaviour, IPunObservable { private Transform thiss; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
thiss = gameObject.transform;
}
public void OnPhotonSerializeView(PhotonStream stream, Photon$$anonymous$$essageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(thiss);
}
if (stream.IsReading)
{
thiss = (Transform)stream.ReceiveNext();
}
}
}`
Hey there,
obviously yes, this is what it will do. To keep the position that you set for this object you have to set it at the instance of your program where it was created. (So where the is$$anonymous$$ine flag of the photonView is set to true). If player A created the object then player B can set a new position all he wants but it will always go back to the position that you transfer every 0.1 seconds from player A.
For this reason: Do not use the stream!! This will just spam so much information over the network but you don't need this at all.
Create an RPC to solve your problem. Remove the transform view, keep the photonview. Remove the stream code setting the position.
Create a function like this:
[PunRPC]
public void triggerDoor(bool value)
{
gameObject.enabled = value;
}
So when you collide/trigger/click/whatever your door you first check if the playerobject who triggers this has is$$anonymous$$ine==true and if yes call this code in your BOB script:
photonView.RPC("triggerDoor", PhotonTargets.All, false);
This will call the $$anonymous$$ethod triggerDoor
on all instances of the game connected to the room. Also it will only be done once. (Saves network traffic)
In case that players are able to join your room later on, consider setting PhotonTargets.All to PhotonTargets.AllBuffered. This way a later joining Player will get the message and will also have the same door status set.
Let me know if something is not clear.
Thanks it worked. But I just got to find out how to link the button to the door and stuff.