Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

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.