Simple RPC on an AI.

I have tried using the scripts from the Marco-Polo tutorial. I am trying to call an RPC on an object when I click the Polo button.
public Transform sheepPrefab;
	// Use this for initialization
	void Start () {
        PhotonNetwork.Instantiate(this.sheepPrefab.name, transform.position, Quaternion.identity, 0);
    	myPhotonView = sheepPrefab.GetComponent<PhotonView>();
}
 
void OnGUI()
{
    GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
 
    if (PhotonNetwork.connectionStateDetailed == PeerState.Joined)
    {
        }
        if (GUILayout.Button("Polo!"))
        {
            this.myPhotonView.RPC("Polo", PhotonTargets.All);
        }
    }
}

My RPC is attached to the instantiated sheepPrefab.
public class SheepNetwork : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	[RPC]
void Polo()
{
    if (!this.enabled)
    {
        return;
    }
 
    Debug.Log("Polo");
}
}

However I am getting two related critical errors and I do not know why.

1:
Received RPC "Polo" for viewID 0 but this PhotonView does not exist! Was remote PV. Remote called.


2:
Illegal view ID:0 method: Polo GO:sheep

Can you tell me why? :)

Comments

  • Btw. the sheep does have a PhotonView. It is however not set at runtime, and I do not know if i need to observe a specific component with RPCs.
  • Hi,

    Script in tutorial uses result of PhotonNetwork.Instantiate(...) to get PhotonView. Also objects instantiated after client joined the room.
    void OnJoinedRoom()
    {
        GameObject monster = PhotonNetwork.Instantiate("monsterprefab", Vector3.zero, Quaternion.identity, 0);
    ...
        myPhotonView = monster.GetComponent<PhotonView>();
    }