Search Unity

Third Party [Photon] How do I add components to the PhotonView ObservedComponents list on runtime?

Discussion in 'Multiplayer' started by N00MKRAD, Jan 15, 2018.

  1. N00MKRAD

    N00MKRAD

    Joined:
    Dec 31, 2013
    Posts:
    210
    For my game, I need to dynamically add and remove transform syncs.

    So far it works, but I always get a NullReference error when I try to add my transform sync to the list.

    This is my code:

    Code (CSharp):
    1. PhotonView RPV = remoteObject.AddComponent();
    2. PhotonTransformView PTV = remoteObject.AddComponent();
    3. PTV.m_PositionModel.SynchronizeEnabled = true;
    4. PTV.m_RotationModel.SynchronizeEnabled = true;
    5. RPV.ObservedComponents.Add(PTV);
    Any ideas?
     
  2. julianwitte

    julianwitte

    Joined:
    Oct 3, 2012
    Posts:
    12
    Your ObservedComponents is null. Make it a new List<Component>() before adding.
     
    Propagant, WonkeeKim and tobiass like this.