Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Parenting Network object as XR Camera

Discussion in 'Multiplayer' started by mohsenz, Sep 2, 2023.

  1. mohsenz

    mohsenz

    Joined:
    Aug 10, 2016
    Posts:
    29
    I'm trying to set XR Camera as a parent of my network object if Photon View is mine,
    My player correctly finds the Camera as a child, but the other players load in 0 0 0,
    I have photonview on my prefab [ownership takeover], saved in Resources, with photontransformview attached,
    What could be the issue?

    Code (CSharp):
    1. public class NetworkPlayer : MonoBehaviour
    2. {
    3.     [SerializeField]
    4.     private string parentPath_vr = "";
    5.  
    6.     PhotonView PView;
    7.  
    8.     private void Start()
    9.     {
    10.         PView = GetComponent<PhotonView>();
    11.     }
    12.     void Update()
    13.     {
    14.         if (PView.IsMine)
    15.         {
    16.             ParentObject(parentPath_vr);
    17.         }
    18.      
    19.     }
    20.  
    21.     public void ParentObject(string path)
    22.     {
    23.         var parent = GameObject.Find(parentPath_vr);
    24.  
    25.  
    26.         Assert.IsNotNull(parent, "Photon view " + gameObject.name + " has an invalid parent gameobject path " + path);
    27.  
    28.         transform.parent = parent.transform;
    29.         transform.localPosition = Vector3.zero;
    30.         transform.localRotation = Quaternion.identity;
    31.     }
    32. }