Loading new scenes: issues and questions

Hey all,

So, since I've no way of knowing much better, when I want my players to jump to a new scene, I send out an RPC that has them all load a new level via Application.LoadLevel(). However, I'm getting a bunch of warnings on both sides saying:

OnDestroy for PhotonView View (0)2001 on Local player but GO is still in instantiatedObjects. instantiationId: 2001. Use PhotonNetwork.Destroy(). Loading new scene caused this.

It seems to be mad at me for loading scenes this way, but I'm not sure how to fix it or what to do differently. Also, since each player is loading the scene at a different rate, there's more room for error with RPCs and syncing (I've had inconsistent issues when loading new levels together). Is there any way to have the players load the scene and wait for everyone else to enter? How do I rid myself of those weird warnings? How should I be loading scenes if not this way?



  • For proper level loading you need to disable networking messages untill you know for sure that everyone is using the same level (otherwise spawn messages get lost in the mainmenu while loading the game)

    The easiest solution is to set this in your mainmenu/preloader:

    PhotonNetwork.automaticallySyncScene = true;

    This will make sure clients always use the same level as the masterclient.
    Also, for level loading, use:
    PhotonNetwork.LoadLevel( .. );

    This will automatically take care of pausing and resuming network messages.
  • Beautiful, I'll try it out later and see if I can get it working relatively painlessly. Thanks for developing such an awesome plugin. :)
  • I was running into issues regarding loading levels once the master client was switched, and I couldn't figure out how to fix it. I came across this thread prior to asking the question myself, and your very simple answer fixed my problem perfectly.

    Leepo & Exit Games: You guys have made a 5-star plugin! I am continually impressed with how flawlessly PUN works with Unity, and how simple the interface is.

    One note: you should probably add this fix to the documentation so that new users don't stumble on the same errors that we did. I noticed that your intro page doesn't even include PhotonNetwork.LoadLevel() (let alone the level sync), it still mentions the messagequeue disable technique that was replaced by LoadLevel().

    http://doc.exitgames.com/photon-cloud/P ... #_messageQ
  • SamusAranX: Thank you! It's so cool to read that our work is helpful :P
    Good point about the doc update. I will take care of that soon.
  • Yeah, I'm actually working on a 2-week Unity multiplayer project for a class and Photon has been invaluable for staying on our target deadline! Unity integrated networking and AllJoyn were both nightmares. (The only requirement of the project is that we make a networked mobile app.)

    Also one more thing: searching for Photon documentation from Google hasn't been very helpful because Google doesn't return accurate results. This makes me think that maybe your website isn't very friendly with Google's web crawlers. I haven't tried any other search engines though.
  • Personally, I'm not so happy with the search either but the pages should be fine indexing-wise. We'll see how we can improve.