Instantiating enemies with RPCManager

Hi, I'm working on a two-player game where players can spawn enemies to attack the other. When each player spawns, I first instantiate the enemy locally and then use an RPCManager to instantiate it on the other player's side (I tried using PhotonNetwork.Instantiate to begin with, but since I needed to update enemies' properties as soon as they were spawned, this was easier). However, now I'm having an issue where player 1 can spawn enemies, but when player 2 tries to spawn an enemy I get an error saying "Received RPC ... but this PhotonView does not exist!" Does anyone know what the cause of this could be? I can post code snippets if it would be useful, but since I don't know where the problem is coming from I'm not currently sure what would be helpful.

Comments

  • It seems you are calling RPCs on some GameObject you didn't properly instantiate yourself.
    Do you use PhotonNetwork.Instantiate and make sure that a PhotonView is on the GameObjects you create?
  • No, because I'm calling the RPC to instantiate the GameObjects. I tried using PhotonNetwork.Instantiate, but because I needed to change the properties of one of the GameObject's scripts after it was instantiated, I thought it would be easier to just instantiate normally using an RPC call.
  • (I tried using PhotonNetwork.Instantiate to begin with, but since I needed to update enemies' properties as soon as they were spawned, this was easier)
    You can set properties with the Instantiation call. (set these via the PN.Instantiate call as last parameter. Then GET these by calling the photonView.instantiationData* in the OnInstantiate* method.

    *= These are not the exact names, please see the API/intellisense.

    Now, back to the error you are getting: Via which PhotonView are you sending the RPC messages? This -must- be done via an existing scene view, it looks like you are sending the RPCs on a locally-instantiated photonview, which will simply not exist on other clients.
  • Leepo wrote:
    (I tried using PhotonNetwork.Instantiate to begin with, but since I needed to update enemies' properties as soon as they were spawned, this was easier)
    You can set properties with the Instantiation call. (set these via the PN.Instantiate call as last parameter. Then GET these by calling the photonView.instantiationData* in the OnInstantiate* method.

    *= These are not the exact names, please see the API/intellisense.

    Thanks, I was able to use this to solve my initial problem of instantiating enemies, though I'm still not sure about the RPC.
    Now, back to the error you are getting: Via which PhotonView are you sending the RPC messages? This -must- be done via an existing scene view, it looks like you are sending the RPCs on a locally-instantiated photonview, which will simply not exist on other clients.

    I sent it using the PhotonView that belongs to the GameObject my RPCManager script was attached to. I pulled this method from some older code that seemed to work fine (the GameObject was instantiated using PhotonNetwork).