- Home /
Tying to parent objects in game with Photon.PUN OnPhotonSerializeView
Hi,
I'm very new to photon and have been trying to use it to implement a multiplayer version of my game. However, I'm not sure what the best approach is to resolve my bug issue.
Basically, in a scene, there are multiple objects with their own part script each, and when the player collides with one of these objects it makes them a child of the player and in turn follows the player. This works fine in single-player and even on the host computer of a multiplayer setting but it fails to synchronize on the other client. It as you would call, very buggy. So much so that when I load it up everything shakes (all parts in the scene) on the client's build.
In order to simplify it for a design perspective, these parts start in the scene as children of an empty jigsaw parent prefab. This empty does not move and once all parts have been picked up, it will have no children Therefore it might be of little relevance. (Experimented giving it a photon view as well)
Once a part is placed it will never move again but because they need to be able to move for a period of time, I have given each part a Photon view and photon transform view component.
I have tried synchronizing the transformed parent through OnPhotonSerializeView on each part but after receiving errors, I have found this not to be accepted. I am trying to be mindful to keep sending to the server to a minimum but I don't really know how to do this.
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
//throw new NotImplementedException();
if (stream.IsWriting)
{
//stream.SendNext(transform.parent); does not work
stream.SendNext(transform.localPosition);
}
else if (stream.IsReading)
{
//transform.parent = (Transform)stream.ReceiveNext(); does not work
transform.position = (Vector3)stream.ReceiveNext();
}
}
Is it even possible to parent an object through the server?
am I better trying to do a different method for my multiplayer version?
Any help would be much appreciated, thank you.
Your answer
Follow this Question
Related Questions
Photon Network Problems 1 Answer
Photon wont sync for the masterclient. 1 Answer
Is this bad for the network? 2 Answers
Unity3D Photon movement synchronization 0 Answers
Photon network problem 2 Answers