How to add a PhotonView by script

Options
Hi guys, I want to add a PhotonView script to my gameobject, I have tried with this.gameObject.AddComponent(); , but when I use it, it throws null.
What Am I doing wrong?
Thanks

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @SebGM2018,

    Thank you for choosing Photon and sorry for the long delay!

    In order to be synchronized over the network, PUN requires GameObject with PhotonView components to be created using one of the following 4 methods:

    - PhotonNetwork.Instantiate
    - PhotonNetwork.InstantiateSceneObject
    - GameObject with PhotonView already in the scene
    - Manual instantiation

    If you want to sync. a GameObject with PhotonView dynamically added at runtime, it's not recommended and could be a lot of trouble.
    Unless the use case really requires this, use one of the methods supported out of the box.