[SOLVED] Received RPC...PhotonView does not exist!
Options
Mishaps
✭
I instantiate a prefab over the network and get it to callback via an RPC after it's spawned. I get it to wait 5 secs before calling back just to be sure. Even though I can see the the local gameobject with ViewID 1000 in the scene I still get this error "Received RPC "rpcname" for viewID 1000 but this PhotonView does not exist!".
How can it not exist when I can see it in the scene :?
Like similar issues I'm only having this on second / third room I try to set up. First room after load always works flawlessly.
How can it not exist when I can see it in the scene :?
Like similar issues I'm only having this on second / third room I try to set up. First room after load always works flawlessly.
0
Comments
-
I tried everything I could think of in my game and no matter what I do I get issues along these lines on the second room my players connect to.
I was able to reproduce them in the marco-polo example. I've attached the code changes I made to the RandomMatchmaker.cs script below. My goal was to make an auto-matchmaker for a simple 2-player game. I altered marco-polo so when you create your own room it waits for 15secs or so and if another player doesn't join then it leaves the room and starts again looking for another room etc. To reproduce my error I start a copy on my phone and one on my laptop. After both players have joined the room I leave the room on the laptop (press the leave button I made) then wait for them to join again and I get this error on my laptop: "Received OnSerialization for view ID 2000. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined" followed by "MissingReferenceException: The object of type 'PhotonView' has been destroyed but you are still trying to access it."
Anything you can think of would be helpfulcheers!
[code2=csharp]using UnityEngine;
using System.Collections;
public class RandomMatchmaker : Photon.MonoBehaviour
{
private PhotonView myMonsterPv;
// Use this for initialization
void Start()
{
PhotonNetwork.ConnectUsingSettings("0.1");
}
void OnJoinedLobby()
{
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed()
{
PhotonNetwork.CreateRoom(null, true, true, 2); // no name (gets a guid), visible and open with 4 players max
}
void OnJoinedRoom()
{
Debug.Log("room joined");
StartCoroutine(spawnWhenHaveTwoPlayers());
}
private IEnumerator spawnWhenHaveTwoPlayers()
{
while (PhotonNetwork.otherPlayers.Length < 1)
{
Debug.Log("waiting for two players...");
yield return new WaitForSeconds(3);
if (PhotonNetwork.room == null) return false;
}
PhotonNetwork.room.open = false;
GameObject monster = PhotonNetwork.Instantiate("monsterprefab", Vector3.zero, Quaternion.identity, 0);
ThirdPersonController controller = monster.GetComponent<ThirdPersonController>();
myMonsterPv = monster.GetComponent<PhotonView>();
controller.enabled = true;
}
void OnCreatedRoom ()
{
Debug.Log("room created");
StartCoroutine(waitForPlayerToJoin());
}
private IEnumerator waitForPlayerToJoin ()
{
for (int i = 0; i < 3; i++)
{
Debug.Log("waiting for an opponent to join my game...");
yield return new WaitForSeconds(Random.Range(2, 8));
if (PhotonNetwork.room == null) return false;
if (PhotonNetwork.room.playerCount > 1) return false;
}
if (PhotonNetwork.room != null) PhotonNetwork.LeaveRoom();
}
void OnGUI()
{
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
if (PhotonNetwork.connectionStateDetailed == PeerState.Joined)
{
GUILayout.Label("waiting for other player to join");
if (PhotonNetwork.otherPlayers.Length > 0)
{
GUILayout.Label("two players in game!");
bool shoutMarco = GameLogic.playerWhoIsIt == PhotonNetwork.player.ID;
if (shoutMarco && GUILayout.Button("\nMarco!\n"))
{
this.myMonsterPv.RPC("Marco", PhotonTargets.All);
}
if (!shoutMarco && GUILayout.Button("\nPolo!\n"))
{
this.myMonsterPv.RPC("Polo", PhotonTargets.All);
}
if (GUILayout.Button("\nLeave\n"))
{
if (PhotonNetwork.room != null) PhotonNetwork.LeaveRoom();
}
}
}
}
// Update is called once per frame
void Update()
{
}
}[/code2]0 -
*bump*
Any ideas? perhaps it's a bug in photon or something I'm doing?0 -
do you correctly tear down previous rooms, that all PhotonNetworkViews are removed?
Means when you leave to the lobby you properly load into a different scene or DestroyImmediate every network prefab in the one you stay to reinstantiate them through Photons Instantiate when you enter the next room?
I ask because all network communication is limited and specific to the room you are in, when you leave the room all network stuff needs to go too.0 -
Thanks dreamora. I only use one scene but I can try the destroyImmediate thing. Do you think photon works better with a multi-scene setup?
You can see how I leave a room in the code in the prev post. Pretty much just use PhotonNetwork.LeaveRoom(). I thought it auto cleans up everything itself.0 -
Mishaps wrote:Thanks dreamora. I only use one scene but I can try the destroyImmediate thing. Do you think photon works better with a multi-scene setup?
You can see how I leave a room in the code in the prev post. Pretty much just use PhotonNetwork.LeaveRoom(). I thought it auto cleans up everything itself.
It works as good there as it does with a single scene.
But with a single scene you are the one forced to do the maintenance and lifecycle handling, where as multiple scenes would move that to the scene cleanups. Most examples are also built around it as all Lite - Room based games normally use 2+ scenes. One for the matchmaking & lobby and one for the real game where the required assets are already cached for fast usage (if you did that in the lobby - matchmaking scene it would take much longer to load at no gain)0 -
Okay. Sounds like you're saying a 2 scene setup would work well for me as it would clean itself up better. Perhaps I should try that.
I can't find anywhere in the documentation or examples that say I should do maintenance myself with a single scene? I'm not really sure what I should do for that anyway. Everything just says this will be taken care of for me. I bought the M2H guide and it had some code for doing "manual cleanup" which I tried but wasn't successful. I saw with TNet they seem to be expecting you to be using multiple scenes when you create a channel too. Perhaps that's the "done thing" for multiplayer.0 -
I reproduced it in the marco-polo example (see prev post). Essentially I only added a "leave room" button. I leave on one device then join again and it gets all those errors. Its a single-scene also so maybe if I tried breaking that up into two scene first it might fix it!0
-
Switching from single-scene to multi-scenes setup resolved all my issues. Thanks go to dreamora for the suggestion.0
-
Thanks for updating us and: cool you two could solve this!
Happy new year0 -
I don't know if I would call this 'SOLVED', rather 'Worked Around'. I seem to be encountering the same issue but splitting into 2 scenes isn't really an option. Are there any documented steps for proper cleanup?0
-
If two rooms for a proper lobby - room split is no option its not hard to do either but you will have to fix your code to do its job properly for setup and teardown.
There is no automatism here to just 'kick off'.
All you need to do is to ensure that all PhotonNetworkViews are gone when you get the OnDisconnectedFromPhoton called upon leaving the room.
Once you received the OnJoinedRoom later on, you can use Photons Instantiate to instantiate all the networked objects correctly that are required in the room.
The reason you see the error otherwise is that the view and especially its view id and registration of the same are bound, exclusive and local to the room in which they were instantiated through Photon or first registered, so upon leaving a room they cease to be valid.
Potentially you could try to request new view ids upon joining the room, but I don't think this is an option for most games if not all anyway as you want a fresh, clean reset state, in which case destroying all 'non global manager' GameObjects and reinstantiating them again when needed is the straight forward and simple way.0 -
If you have problems with view IDs, you could try out the new version of PUN please. The new editor scripts should make sure every view in scene has a proper id.
Find the download and discuss here: viewtopic.php?f=17&t=2333
The problems you have are maybe unrelated and not fixed by 1.18, though:
There's still a known issue with instantiating objects in a scene before loading new scenes: Instantiated Game Objects are not cleaned from the server when you just load a new scene but they get cleared from the client. This means that the GOs are not in sync and one client might update objects that others already destroyed (by loading).
Currently, a way to avoid this is to use PhotonNetwork.RemoveAllInstantiatedObjects(PhotonNetwork.player) to clean up your instantiated objects (on server) before you load a new scene.
I will look into automatically cleaning up those objects when they get destroyed (no matter why).
About matchmaking:
You should not use a room to match players, then get into another room to play. Aside from chatting while waiting, this is more or less random matchmaking and that's best done by the (master)server for you. Try to match randomly first and if that fails, create a room. If everyone does this, your rooms will fill up asap (depending on the number of players).
http://doc.exitgames.com/photon-cloud/M ... references0 -
Mishaps:
I know it's been a while since you posted your code. Now that Im more or less done with the PUN update, I tried it.
Your room gets closed and when one player leaves, the other stays alone forever, waiting in a closed room for more players. Maybe I didn't get exactly how you produce the issue.
I added code to open the room 5 seconds after one player left. Now leaving means that temporarily 2 games are open until the first player decides to leave and look for a game again.
I can't reproduce the issue in 1.18 with Marco Polo and your code. Can you?0 -
I'll check it out when I get the chance. How do I upgrade to 1.18? It still says 1.17 on the asset store.0
-
Mishaps wrote:I'll check it out when I get the chance. How do I upgrade to 1.18? It still says 1.17 on the asset store.
It has been released as a preview linked in a sticky thread here on the PUN board or viewtopic.php?f=17&t=23330 -
cheers thanks for the link dreamora0
-
Hi All I have made multiplayer game,it works fine (all thigns sync).But when I change the scene to restart game with this code :
1- PhotonNetwork.LeaveRoom(); // on button click
void OnLeftRoom(){
PhotonNetwork.LoadLevel("Menu");
}
then i create a new room add players to it(everything seems ok until now) but when i shift to gamescene the master clinet initialized all players but non master client does not although they are both on same level.The following messages from client side popup.
Warning:
Received RPC for viewID 1001 but this PhotonView does not exist! Was remote PV. Owner called. By: 1 Maybe GO was destroyed but RPC not cleaned up.
Warning:
Received OnSerialization for view ID 1001. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined.
Note: same messages pop up while doing PhotonNetwork.Disconnect() and leaveRoom().
Thanks in advance!0 -
Note:
players on clinet side did not instantiate also.0 -
A viewID 1001 should be a networked object by player 1.
Maybe loading the scene is causing this: When you join a room, you immediately get the custom properties and get the cached events (PN.Instantiate, e.g.). You need to make sure that you don't load a scene after you already instantiated something that should be in the room. Loading a scene will destroy game objects (unless you load additively or such).
Read "Timing for RPCs and Loading Levels" on this page:
https://doc.photonengine.com/en-us/pun/current/getting-started/feature-overview#_messageQ
If this doesn't help, you can run the SupportLogger to log the events/actions to the console and make sure everything happens in the sequence that you expect. What is different in the second attempt?!
0 -
I had this problem and solved it by moving RPC call from Awake method to Start. Probably on Awake method call the object is not fully constructed and it can't receive the RPC call from himself if you have set the PhotonTargets.All0