- Home /
Photon Networking: LocalScale transform doesn't work
Hi, I'm using Photon to instantiate an object, with "Transform Serialization" set to "All". I wrote a script for each Vive Controller, with one I'am able to grab and rotate/reposition the object. With the other I can rescale it. Basically:
pickup.transform.localScale += new Vector3(pickup.transform.localScale.x * 0.01F, pickup.transform.localScale.y * 0.01F, pickup.transform.localScale.z * 0.01F);
The problem is, that while the objects' position and rotation is being synced (it disappears as it's "grabbed" but reappears at the correct position and in correct rotation so that's ok), the change in scale isn't.
Or to put it simply: I can reposition and rotate the object, which the client is seeing just fine, but when I scale it, it always stays at 100% scale from the clients perspective.
Ironically, when I disconnect the client and reconnect again, the sizes will refresh to their scaled values. But I would have to do this anytime I rescale an object on the host...
I've tried writing a custom Photon script and attached it to the instantiated prefab as observed component, but it doesn't change anything:
public class PhotonObject : Photon.MonoBehaviour
{
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(transform.localScale);
}
else
{
this.transform.position = (Vector3)stream.ReceiveNext();
this.transform.rotation = (Quaternion)stream.ReceiveNext();
this.transform.localScale = (Vector3)stream.ReceiveNext();
}
}
}
I have also tried to change the "send" part of the script to something like:
Vector3 objectSize = Vector3.Scale(transform.localScale, this.GetComponent<Renderer>().bounds.size);
stream.SendNext(objectSize);
I don't know why but it gives me weird proportions on the objects spawned at the client side. And while the scaling does somehow seem to work, it's much larger on the client side than on the hosts side (e.g. host scales it to 200%, client syncs scale to 800%).
I'm really stumped with this one. Any help would be highly appreciated!
I've already google searched every keyword possible, and followed Photons Marco Polo Tutorial, still no solution unfortunately.
Thank you!
Answer by Sab44 · Aug 04, 2017 at 02:30 PM
Okay, I somehow solved it by changing the "Observe Option". With "Reliable Delta Compressed" the scale was not synced, if it's being changed to "Unreliable (on Change)" it works.
What's still weird, is that the object disappears while being interacted with for everyone else but the player interacting with it, but reappears in correct position, rotation and scale once the interaction is over.
Your answer
Follow this Question
Related Questions
Syncing localScale 0 Answers
PUN2 Chess game instantiation problem 2 Answers
Photon player RaiseEvent sending bools 1 Answer
Question regarding unity mobile multiplayer game 0 Answers
Unity Editor Crash !!! 0 Answers