Cannot serialize a Camera component

marfmarf
Hi, I'm making an online fps and I have a problem, this is my setup for damage and for the kill of the player:

when I shoot I use bullets, each bullet has a script attached to it, in the script there's a variable called killCam that is of type Camera and it has the value of the Camera component of the player that shoots.
When I hit someone I set the variabile killCam (it's of type Camera but it is in PlayerManager.cs, another script) via a SendMessage function.
Finally when the player dies I call an RPC called KillPlayer and I pass to the RPC the killCam as parameter, the problem is that it game me those errors:
Illegal view ID:0 method: KillPlayer GO:Player
UnityEngine.Debug:LogError(Object)
NetworkingPeer:RPC(PhotonView, String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2204)
PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1459)
PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/Extension/PhotonView.cs:165)
PlayerManager:ApplyBulletDamage(String) (at Assets/Scripts/MultiPlayer/PlayerManager.cs:163)
UnityEngine.Component:SendMessageUpwards(String, Object, SendMessageOptions)
Projectile:OnCollisionEnter(Collision) (at Assets/Scripts/MultiPlayer/Weapons/Projectile.cs:56)
SystemException: cannot serialize(): UnityEngine.Camera
ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.SerializeObjectArray (System.IO.MemoryStream dout, System.Object[] objects, Boolean setType)
ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.SerializeHashTable (System.IO.MemoryStream dout, System.Collections.Hashtable serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.SerializeParameterTable (System.IO.MemoryStream memStream, System.Collections.Generic.Dictionary`2 parameters)
ExitGames.Client.Photon.Protocol.SerializeOperationRequest (System.IO.MemoryStream memStream, Byte operationCode, System.Collections.Generic.Dictionary`2 parameters, Boolean setType)
ExitGames.Client.Photon.EnetPeer.SerializeOperationToMessage (Byte opc, System.Collections.Generic.Dictionary`2 parameters, EgMessageType messageType, Boolean encrypt)
ExitGames.Client.Photon.EnetPeer.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypt, EgMessageType messageType)
ExitGames.Client.Photon.PeerBase.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypted)
ExitGames.Client.Photon.PhotonPeer.OpCustom (Byte customOpCode, System.Collections.Generic.Dictionary`2 customOpParameters, Boolean sendReliable, Byte channelId)
LoadbalancingPeer.OpRaiseEvent (Byte eventCode, System.Collections.Hashtable evData, Boolean sendReliable, Byte channelId, EventCaching cache, ReceiverGroup receivers) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/LoadbalancingPeer.cs:320)
NetworkingPeer.OpRaiseEvent (Byte eventCode, System.Collections.Hashtable evData, Boolean sendReliable, Byte channelId, EventCaching cache, ReceiverGroup receivers) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:707)
LoadbalancingPeer.OpRaiseEvent (Byte eventCode, System.Collections.Hashtable evData, Boolean sendReliable, Byte channelId) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/LoadbalancingPeer.cs:235)
NetworkingPeer.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2226)
PhotonNetwork.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1459)
PhotonView.RPC (System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/Extension/PhotonView.cs:165)
PlayerManager.ApplyBulletDamage (System.String data) (at Assets/Scripts/MultiPlayer/PlayerManager.cs:163)
UnityEngine.Component:SendMessageUpwards(String, Object, SendMessageOptions)
Projectile:OnCollisionEnter(Collision) (at Assets/Scripts/MultiPlayer/Weapons/Projectile.cs:56)

Before I used the killCam all worked.

Thanks and regards,


Marco

Comments

  • The Camera is not a supported, serializable datatype.
    That means: If you try to send it, the code doesn't know how to pass the essential data of this cam to the other players.
    This breaks your attempt to send it and gives you the "cannot serialize(): UnityEngine.Camera" exception.

    You could make it serializable. Have a look at the class CustomTypes. It contains de/serialization methods for Vector3 and other classes and those are registered when the game starts.
    For a Camera, I would suggest that you send the complete translation, target, FOV and maybe some other values, too.


    In your case, the actual info you need is something else: Who shot?!

    The info who sent an event (or an RPC or anything via OnPhotonSerializeView) is already contained in the message we send. Instead of sending "the cam belonging to player who shot", you can better find out who shot (which is already taken care of) and then find the cam of that player. Saves you a bunch of data to send.
  • Ok, thank you very much.
Sign In or Register to comment.