adding PhotonTransformView programatically

Hi

Is there a way to add PhotonTransformView component to your object programmatically? I have to add it to tons of objects if I do it manually on each prefab and I'm sure you can do addComponent on it from a script but the problem is that I don't seem to have access to enable the synchronize position/rotation from script and all its parameters. Is there a way to do it?

Comments

  • Hi @creat326,

    well actually there is a way to do so, but this is not recommended. You can navigate to the PhotonTransformView class and look for m_PositionModel, m_RotationModel and m_ScaleModel. These are private by default so you can't access them from outside. Making them public gives you the possibility to modify them via code. The following is for adding a PhotonTransformView component and setting things up.
    PhotonTransformView view = gameObject.AddComponent<PhotonTransformView>();     
    view.m_PositionModel.SynchronizeEnabled = true;
    
    PhotonView pView = GetComponent<PhotonView>();
    pView.ObservedComponents = new List<Component>();
    pView.ObservedComponents.Add(view);
    Again: this is not recommended and we won't give any further support on this. :)

    --------------------------------------------------

    In the Unity Editor you have the possibility to select multiple prefabs and attach components to all of them. You can do so by selecting multiple prefabs and click on 'Add Component' in the inspector. This might be an easy way to attach components to multiple prefabs and saves a lot of time. You can also edit multiple selected prefabs this way.
  • glitchbeam
    edited October 2017
    @Christian_Simon it would be great if this was an official change. We're adding assets via assetbundles and must add components at run-time.

    In the meantime, I have created a copy of the PhotonTransformView so it's not overwritten during future updates. Having it as an official change would be greatly appreciated.

    Thanks!
  • Hello people, I'm dealing with the same issue, I need to setup the photonTransformView component via an EditorWidow script, but I can't because this restriction.
    I think making m_PositionModel, m_RotationModel, m_ScaleModel and other private members protected in the official source code would be great so we could extend this class and create some setters.
    Other solution would be to make them public members so we can set them up.
    On the other hand, I don't really like the idea of creating my own photonTransformView because the lack of support on the future.

    Anyways, would be great to see a solution for this.
    And Congrats for the great job you are doing with Photon.