ObserveOption always "off" for newly instanced objects


I'm instancing an object with Unity, then adding a PhotonView to it, then calling that object's RPC.SpawnOnNetwork function:

[code2=csharp][RPC] // Make the object visible to all other players on the network.
void SpawnOnNetwork(Vector3 pos, Quaternion rot, int id1)
PhotonView[] nViews = gameObject.transform.GetComponentsInChildren<PhotonView>();
nViews[0].viewID = id1;
// pv.viewID = id1;


Then, I set it's Observed value to itself: obj.photonView.observed = obj.transform

However, if I look at the object after it was instanced in the inspector, it's "observe option" is always "None", and I can't seem to get the observe option to change via script. Am I doing something wrong?



  • To clarify, all I'm trying to do is instance an object (which I do by GameObject.CreatePrimitive), add some values to it, then make it totally visible to everyone else on the network via PhotonView.
  • You might not be able to call and RPC on some GO to assign a viewID to that PhotonView. It needs the viewID to be identified and get RPCs called on it in the first place.
    So to manually assign viewIDs you will need another (probably static) GO which executes RPCs that will assign the viewIDs. In that case, the instantiation can be done in those methods as easily. Instantiate, add a PV, assign a viewID to that GO's PV.
  • I created a view Id manager which I attached to an empty game object. But when I try to reference this object and call AssignViewID using the command "viewIdManagerCom.RPC("AssignViewID",PhotonTargets.AllBuffered,newNumber);", it returns an error: Assets/_Scripts/NumberManager.cs(562,42): error CS1061: Type `ViewIDManager' does not contain a definition for `RPC' and no extension method `RPC' of type `ViewIDManager' could be found (are you missing a using directive or an assembly reference?)

    [code2=csharp]using System;
    using System.Collections.Generic;
    using UnityEngine;

    public class ViewIDManager : Photon.MonoBehaviour {

    void AssignViewID(GameObject newObj){
    int id1 = PhotonNetwork.AllocateViewID();
    PhotonView pv = newObj.AddComponent<PhotonView>();
    pv.viewID = id1;
    pv.observed = pv.transform;