Getting exception after instantiation

Options

Im not sure what does it means. + my animation not synch :

there prefab that holds the viewanimator that get unity instantiation for the model. the parent (the player) have the photonview, and he does recognize the animatorview, but the animation are not synch - I can see only the idle animation playing.

this is the error im getting :

IndexOutOfRangeException: Index was outside the bounds of the array.

Photon.Pun.PhotonStream.PeekNext () (at Assets/Photon/PhotonUnityNetworking/Code/PunClasses.cs:595)

Photon.Pun.PhotonAnimatorView.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonAnimatorView.cs:559)

Photon.Pun.PhotonView.DeserializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:544)

Photon.Pun.PhotonView.DeserializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:534)

Photon.Pun.PhotonNetwork.OnSerializeRead (System.Object[] data, Photon.Realtime.Player sender, System.Int32 networkTime, System.Int16 correctPrefix) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1867)

Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2238)

Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3364)

ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at <b01774392bf441f59388585f8e74649d>:0)

ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at <b01774392bf441f59388585f8e74649d>:0)

ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at <b01774392bf441f59388585f8e74649d>:0)

Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:226)

Rethrow as AggregateException: Caught 1 exception(s) in methods called by DispatchIncomingCommands(). Rethrowing first only (see above). (Index was outside the bounds of the array.)

Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:244)

Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:145)

this is the script that instantiate the prefab that have animator view :

  private void Start()

  {

    CreatePlayerModel(PlayerGender.Female);

  }


  public void CreatePlayerModel(PlayerGender gender)

  {

    if (gender == PlayerGender.Male)

    {

      currentModel = Instantiate(maleModel, gameObject.transform);

    }

    else

    {

      currentModel = Instantiate(femaleModel,gameObject.transform);

    }

    playerMovement.animatorController = currentModel;

  }

Answers

  • Tobias
    Options

    You need to use PhotonNetwork.Instantiate, if you want to have networked objects (not just local ones).

    Read and code-along the PUN Basics Tutorial which explains most details.

    About the exception: You seem to be reading more elements from the PhotonStream than the origin sent. Check the Count value and if you detect values missing, log instead.