Can't make PhotonView.ObservedComponents.Add work
Options
Hi, i want to set ObservedComponents by code and i can't get it working properlly:
Unity throws the following error on third line:
¿How can i get pView instance if this is not the right way?
I can only get it working by setting:
¿But what if i want to observe more components?
GameObject prefab = new GameObject(); PhotonView pView = prefab.AddComponent<PhotonView>(); pView.ObservedComponents.Add(prefab.transform);
Unity throws the following error on third line:
NullReferenceException: Object reference not set to an instance of an object
¿How can i get pView instance if this is not the right way?
I can only get it working by setting:
pView.observed = prefab.transform; pView.synchronization = ViewSynchronization.UnreliableOnChange;
¿But what if i want to observe more components?
0
Comments
-
hmm I dont know if you can add observed components like that (i didnt find anything on the documentation).
Have you tried having the gameobject as a prefab in the editor (with photonview and transform as observed component added manually from the editor)0 -
I can't, the prefab is fully created in c# (PrefabUtility.CreateEmptyPrefab)0
-
I think the ObservedComponents list is empty when you create the prefab like this. Create a list and add it then?0