Photon generating / returning only view id 0 ???

Options
Hi there

So I have a setup where, if you click on "create room", I then load a prefab that contains a PhotonView component. I then do this:
static public bool IsServer = false;
	static public int MaxConnections = 16;
	void Start() {		
		DontDestroyOnLoad(gameObject);
		PhotonNetwork.playerName = AccountDetails.PlayerName;
		PhotonNetwork.ConnectUsingSettings("v1.0");
	}
	IEnumerator SendRegisterMessage() {
		string testView = "";
		do {
			PhotonView photonView = PhotonView.Get(this);
			testView = ""+photonView;
			print("Waiting for " + testView + " to change. Index = " + testView.IndexOf("View 0") );
			yield return new WaitForSeconds(0.5f);
		} while (testView.IndexOf("View 0") == 0);
		print("Done Waiting. ViewID is now " + testView);
		photonView.RPC("RegisterPlayer", (JoinAutomatically) ? PhotonTargets.AllBuffered : PhotonTargets.All,
        				AccountDetails.PlayerName,
        				AccountDetails.AccountInfo[2].String("avatar"),
        				PhotonNetwork.player);
    }
    void OnJoinedRoom()
    {
        Debug.Log("We have joined a room.");
        StartCoroutine(SendRegisterMessage());
    }
    public void OnReceivedRoomList()
    {
        Debug.Log("OnReceivedRoomList");
	Rooms = PhotonNetwork.GetRoomList();
	if (IsServer) {
		StatusMessage.Message = "Connecting as server";
        	string[] exposedProps = new string[1];
        	exposedProps[0] = "gametype";
		PhotonNetwork.CreateRoom(roomname, true, true, MaxConnections);
	}
    }
    public void OnConnectedToPhoton()
    {
	if (!IsServer) {
		StatusMessage.Message = "Connecting as client";
		PhotonNetwork.JoinRandomRoom();
	}
    }

What SHOULD be a very straightforward thing to do is giving me 3 problems:
1. I cannot crate a room in OnConnectedToPhoton because creating a room gives me an error saying "Not authorised". So instead, when I click on "Create room" I must first wait tillI get a list of existing rooms before I can can call CreateRoom ... Huh? Where is the logic in THAT?

2. I cannot send an RPC message after I joined a room because PhotonView.Get(this) returns 0 and I get an error when I try to send a message to ViewID 0. So I placed the message inside a coroutine to wait for the function to return anything other than 0 but it just stays on 0 forever... until I click on the prefab in the Heirarchy. As soon as I click on the prefab, the ViewId in the inspector lists it as 1 and the coroutine completes as expected... What is UP with that?!!?

3. as I read the documentation, PhotonView.viewID is of type int but when I say "if (photonView.viewId > 0)" I am given the old "You cannot use > with a left side of type viewId and right side of type int"-message meaning I am left to resort to "if (somestring.IndexOf("View 0")" in order to get the view Id number... Why is that then?

I have been stuck for an entire day now just trying to create a room and sending a buffered RPC as soon as I join the room. I keep reading with Photon I will be up and running in minutes and yet it has taken me over 8 hours no just to create a room and send a single RPC...

I am now resorting to trickery by manually creating a reference to the ViewID and using the reference, rather than the way used in the demos and tutorials. And placing my "create room" code inside the "on room list received" section... This is really beginning to look really shitty...

Can someone PLEASE help me to get past this? Thanks

The ultimate goal is to do this:
A player clicks on create room after selecting max size
- A room is created and his avatar is loaded and buffered
- Once the room is full, he clicks the "start match" button and all players receive an RPC to load the level

Alternatively...
A player clicks on join room and goes into the match waiting area
- As soon as he enters the room, he gets the buffered msgs to load the avatars of all connected players
- player then just sits and stares at the avatars of the opponents until the masterClient starts the match

Done... All I've been trying to do all day! Except... I want to encapsulate ALL f this inside a prefab. A player clicks either on create or join and I then set the appropriate static values in the prefab's class and then instantiate the prefab. I want the prefab to start, connect, create/join the room, buffer the avatar of each player as they enter the room and initiate the level loading...

Comments

  • Oh, I did forget to mention that by adding:
    public PhotonView ThisView;
    	void Awake() {
    		PhotonNetwork.playerName = AccountDetails.PlayerName;
    		PhotonNetwork.ConnectUsingSettings("v1.0." + MaxConnections);
    		
    		if (null == ThisView)
    			ThisView = (PhotonView)GetComponent<PhotonView>();
    	}
    
    ...it also still reports the viewID as 0 until I click on the prefab in the scene. Only THEN does it update to 1...
  • Well, I managed to make some progress (finally)
    I managed to get this to load without problems for the masterClint, now I just need to solve the "Not authorised" error on the JoinRandom of the client...

    So, the leeway I managed to create was by discovering that the documentation is wrong in saying that PhotonView.viewID is an int. It is in fact a PhotonViewID and the int is accessible INSIDE it via "ID". So, then I manually created an ID of 1 (which I would have set in the inspector if I were able) and assign that to the network view I instantiate at runtime. I figure if I create the network view ID myself and simply set it to the same value for all, then it MUST work... right? So here is my code... See if you can improve on it, please...
    void Awake() {
    		PhotonNetwork.playerName = AccountDetails.PlayerName;
    		PhotonNetwork.ConnectUsingSettings("v1.0");
    		
    		if (null == ThisView) {
    			PhotonViewID ThisID = new PhotonViewID(1, null);
    			ThisView = gameObject.AddComponent(typeof(PhotonView)) as PhotonView;
    			ThisView.viewID = ThisID;
    		}
    	}
    

    Also, the thing with the rooms not being able to be created until after a room list has been fetched... seems that is expected behaviour so to prevent unwanted behaviour I just moved the RPCs I want to send out of the "on room list fetched" section and created a coroutine during the "on room created" section.

    To think... I decided to use this instead of Unity networking because I thought this was going to be easier... *koff koff* :cry::(