Manually Spawning PhotonViews

Options
I'm having difficulty setting spawning of photonViews up, can anyone shed any light on how to do it?

I have to use RPCs to set up a player object, because of the way the player is created (there's a control object, then a graphics object, and the two have to be parented and linked up... it would take too long to convert to PN.Instantiate, and would be more complex)

There's the problem of buffering other users' objects so that when you join, you see the pre-existing players. I'm trying to create them manually using the following code:
[code2=javascript]function Start () {
for (var pPlayer in PhotonNetwork.otherPlayers) {
iV(pPlayer.ID, 0, pPlayer.name, 0, 0, 0, 0);
}
}

@RPC
function iV(viewID : int, vehId : int, vehName : String, isBot : int, isIt : int, score : int, specialInput : int) {
var pos : Vector3 = World.base.position;
while(Physics.CheckSphere(pos, 3)) pos += Vector3.up;

var plyObj : GameObject;
plyObj = Instantiate(objectVehicle, pos, Quaternion.identity);

plyObj.GetComponent(PhotonView).viewID = viewID;
}[/code2]

I'm getting the following error:
Received RPC "xxxx" for viewID 1001 but this PhotonView does not exist!
UnityEngine.Debug:LogError(Object)
NetworkingPeer:ExecuteRPC(Hashtable, PhotonPlayer) (at Assets/Plugins/PhotonNetwork/NetworkingPeer.cs:1588)
NetworkingPeer:OnEvent(EventData) (at Assets/Plugins/PhotonNetwork/NetworkingPeer.cs:1437)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Plugins/PhotonNetwork/PhotonHandler.cs:65)

Is it actually possible to spawn photonviews this way and have them sync as though they were PN.Instantiated? and if so, how?

Comments

  • Tobias
    Options
    If you instantiate manually, things like this could happen. We log it as error but maybe actually it depends on your usage if it's an error or not.
    Background:
    Some player instantiates a view and sends it's RPCs through it. The instantiate happens first for everyone in the game and all rpcs sent after Instantiation will naturally find their target.
    Now, if someone joins a room, the others might already use some viewID to identify an object. If the new player dispatches incoming messages before it creates the target objects, you get this error.

    I fear I can't really solve the problem for you. It's related to networking in general and depends on your game.
    Try to get instantiation done earlier or remove the error message for your manually instantiated objects (but make sure you won't miss stuff this way).
  • Ace_
    Options
    Hmm... that's odd, I do the instantiation straight away. I'll look into it. Thanks for the information though! :)