Network.Instantiate oddities

I'm having problems where the game state seems to be fine on the master client, but on other clients, they can't see all the instantiated objects. Additionally, they don't interact with objects correctly. This is my first question, and I'm not really sure what information would be helpful for you guys to help, but if you tell me I'll edit my post with more detail!



  • It's also difficult to ask the right questions to get all info needed. Let's try together :)

    Does this happen all the time or just sometimes? Did you notice steps to reproduce? Can you force a certain issue to happen all the time? If so, what are the steps to this and how does it behave "wrong"?
    Also: Any info in the log / console?
  • Yeah, it happens all the time! I'll quickly run through how the code works and that might help?

    So the game starts on the main game lister, which displays a list of current games, using PhotonNetwork.GetRoomList();

    One player creates a room using "PhotonNetwork.CreateRoom($gameName$,true,true,4);". This then loads a lobby room (different scene) where players select their team. In the lobby scene, the MasterClient spawns the chat object which controls the team selection e.t.c. This works fine, players can change team e.t.c. perfectly

    However, once the master Player clicks start, and we load the main game screen, things go wrong.

    This is the code that happens when the game starts (in the Start of a spawner object in the scene)

    [code2=csharp]myPlayer = PhotonNetwork.Instantiate("CapsuleCharacter",Spawners[WarpBall.slot].transform.position,Quaternion.LookRotation(Spawners[WarpBall.slot].transform.position-ballSpawer.transform.position),2) as GameObject;
    myPlayer.GetComponent<WarpPlayer>().spawner = this;
    Camera.mainCamera.gameObject.GetComponent<MouseOrbit>().target = myPlayer.transform;

    The masterserver sees everything that should be spawned, but the other clients only see their own characters and nothing else. Master server has no warning logs, but the clients get:
    "Received OnSerialization for view ID 1002. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined
    NetworkingPeer:OnSerializeRead(Hashtable, PhotonPlayer, Int32, Int16) (at Assets/Plugins/PhotonNetwork/NetworkingPeer.cs:2632"

    this help at all? If you wanted I could send a copy of the project?
  • I think this has to do with loading a new scene. In that case, messages from the master might arrive while the engine changes scenes and this leads to problems with spawing the required game objects. They might show up in the old scene in such a case.

    You can usually solve this by stopping the message queue. This keeps incoming events from being executed while you load stuff.
    Read "Timing for RPCs and Loading Levels" on this page: ... #_messageQ

    If you want to verify that all clients are ready to start, they could set a property "r" (for "ready") to true. Make sure to re-set the state before a client joins another room. You can do this locally before you join a room: PhotonNetwork.player.SetCustomProperties().
  • That worked wonderfully! I only have two more questions:

    1. I seem to be having trouble setting a javascript script as the observed object in the photonview. I get the following message:
    Tried to run OnPhotonSerializeView, but this method was missing on: CapsuleCharacter(Clone) (PlayerLocal)
    NetworkingPeer:ExecuteOnSerialize(MonoBehaviour, PhotonStream, PhotonMessageInfo) (at Assets/Plugins/PhotonNetwork/NetworkingPeer.cs:2522)
    NetworkingPeer:OnSerializeWrite(PhotonView) (at Assets/Plugins/PhotonNetwork/NetworkingPeer.cs:2540)
    NetworkingPeer:RunViewUpdate() (at Assets/Plugins/PhotonNetwork/NetworkingPeer.cs:2459)
    PhotonHandler:Update() (at Assets/Plugins/PhotonNetwork/PhotonHandler.cs:71)

    I suppose i can port the script to C#, but it would be nice if i didn't have to.

    2. The non-master client seems to have trouble destroying my ball (which is spawned with PhotonNetwork.instantiate by the master client). Should I be spawning it with PhotonNetwork.InstantiateSceneObject?
  • 1: Did you move the Plugins folder from PUN into the Assets root folder? That's needed to make C# scripts available for JS. This should also allow you to "observe" JS scripts. If that's not the case, we can look for a solution. Cross-language usability is heavily depending on Unity.

    2: Any client will have trouble deleting another client's objects. From Unity's networking, we took the concept of ownership. Whoever creates something will own it and is the only one who moves or destroys the object again. You might send an RPC to the master to destroy it or do it implicitly (health = 0 or similar).
    Of course, you could destroy a GO locally but that won't remove it from the scene for anyone else.