Errors When Networking Triggers with PhotonAnimatorView

Options
I'm trying to use a PhotonAnimatorView to network my triggers, but I get this error when I enable synchronization for said triggers

InvalidCastException: Cannot cast from source type to destination type.
NetworkingPeer.ObjectIsSameWithInprecision (System.Object one, System.Object two) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3586)
NetworkingPeer.DeltaCompressionWrite (.PhotonView view, ExitGames.Client.Photon.Hashtable data) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3456)
NetworkingPeer.OnSerializeWrite (.PhotonView view) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3322)
NetworkingPeer.RunViewUpdate () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3200)
PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:90)

I don't think it's anything in my code because none of my scripts are listed in the error. Is this a known issue? Have I done something wrong? I have a PhotonView and PhotonAnimatorView on my character prefab. PhotonView is observing PhotonAnimatorView. Is there anything else I need to do?

Comments

  • Tobias
    Options
    Can you try the new version of PUN and let us know if the issue persists?
    If you have a small repro case, it would help us, if you could send a download link for it to: developer@exitgames.com (or post it publicly, if that's ok for you).
  • I had to delete/reinstall PUN. The Asset Store didn't give me an option to update. However, now I can't even connect to a server. After Connect() gets called, it just sits there and does nothing. Has something changed in the way one connects to Photon servers?
  • Alright, I've gotten my game connecting to Photon again, but now PhotonAnimatorView doesn't throw any errors... but it also doesn't network my triggers. I've tried both continuous and discreet sync. Are triggers just not supported yet or something?
  • Skar
    Options
    Had the same issue. Ended up adding every trigger event to a list, then continuously check, send and remove the first index of that list in OnPhotonSerializeView.
  • Could you go into a bit more detail on how you did that, Skar?
  • Skar
    Options
    I have a switch statement for every time an attack is used, which sets the appropriate trigger. When the trigger is set, I store the nameHash of the parameter name in a List.
    protected void attackSwitch(string animName)
    {
    	for(int i = 0; i < anim.parameters.Length; i++){
    		if(animName.Equals(anim.parameters[i].name)){
    			int hash = anim.parameters[i].nameHash;
    			animList.Add(hash);
    		}
    	}	
    }
    I then check if the list currently has a value in OnPhotonSerializeView(), and send it:
    void SerializeTriggers(PhotonStream stream)
    {
    	int id = 0;
    	if(this.m_animList.Count > 0){
    		id = this.m_animList[0];
    		this.m_animList.RemoveAt(0);
    	}
    	stream.SendNext(id);
    }
    And Deserialize it on receiving clients:
    void DeserializeTriggers(PhotonStream stream)
    {
    	int id = (int)stream.ReceiveNext();
    	if(id != 0)
    		m_Animator.SetTrigger(id);
    }
    I had some problems with only serializing a value if there was one to be sent, so I ended up just sending 0 if there is no trigger in the list.

    Not really sure how great this is performance wise, but it seems to be working fine at the moment.
    In the future I think I'm gonna atleast send attack animation triggers with the RPC I'm already sending for the attack.
  • Wow, I was really overcomplicating things when trying to roll my own solution. I was already sending an RPC to toggle the collider for the melee weapon's collider... still not sure if that's the right thing to do regarding networked melee combat, but it's there and it at least works as a conduit for a string that I use to trigger the animation over the network. So, it's working with an RPC and it works great, so thanks for that piece of advice :)

    [PunRPC]
    public void toggleCollider_RPC(int playerId, string ownedBlade, string swordTrigger)
    {

    Transform playerT = PhotonView.Find(playerId).transform;
    playerT.Find("pirateFinal_rig/Armature/Hip/Spine/Chest/shoulder_R/bicep_R/forearm_R/hand_R/RH_WP/" + ownedBlade).GetComponent().changeLayer();
    if (swordTrigger != "") {
    playerT.GetComponent().SetTrigger(swordTrigger);
    }
    }