Exception:Cannot Serialize()

Options
I get an error when I try to send a RPC containing custom parameters and types:

[code2=csharp]Exception: cannot serialize(): BlockData
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, ExitGames.Client.Photon.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, Byte interestGroup, ExitGames.Client.Photon.Hashtable customEventContent, Boolean sendReliable, Byte channelId) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/LoadbalancingPeer.cs:443)
NetworkingPeer.OpRaiseEvent (Byte eventCode, Byte interestGroup, ExitGames.Client.Photon.Hashtable evData, Boolean sendReliable, Byte channelId) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:772)
NetworkingPeer.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2651)
PhotonNetwork.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1907)
PhotonView.RPC (System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:254)
Builder.Update () (at Assets/Assets/Prefabs/Player/Scripts/Builder.cs:65)[/code2]

I'm trying to sync the scene over the network.
I have 2 scripts: one is on my player object with a photonView sending the RPC. The other is a scene object also with a photonView recieveing the RPC and setting the values.

Script 1 (Builder.cs):

[code2=csharp].........
if( Input.GetMouseButtonDown(1) ) { //left click
Vector3i? point = GetCursor(false);
if(point.HasValue) {
bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, characterCollider).HasValue;
if(empty) {
BlockData block = new BlockData( selectedBlock );
block.SetDirection( GetDirection(-transform.forward) );
map.SetBlockAndRecompute(block, point.Value);//set empty block as selected block
if(PhotonNetwork.connected)photonView.RPC("Set", PhotonTargets.All, block, point.Value);
}
}
}
........[/code2]

Script 2(Map.cs):

[code2=csharp]........
public void SetBlockAndRecompute(BlockData block, Vector3i pos) {
SetBlock( block, pos );
//if(PhotonNetwork.connected) photonView.RPC("Set", PhotonTargets.All, block, pos);


Vector3i chunkPos = Chunk.ToChunkPosition(pos);
Vector3i localPos = Chunk.ToLocalPosition(pos);

SetDirty( chunkPos );

if(localPos.x == 0) SetDirty( chunkPos - Vector3i.right );
if(localPos.y == 0) SetDirty( chunkPos - Vector3i.up );
if(localPos.z == 0) SetDirty( chunkPos - Vector3i.forward );

if(localPos.x == Chunk.SIZE_X-1) SetDirty( chunkPos + Vector3i.right );
if(localPos.y == Chunk.SIZE_Y-1) SetDirty( chunkPos + Vector3i.up );
if(localPos.z == Chunk.SIZE_Z-1) SetDirty( chunkPos + Vector3i.forward );

SunLightComputer.RecomputeLightAtPosition(this, pos);
LightComputer.RecomputeLightAtPosition(this, pos);
}
..........

[RPC]
public void Set(BlockData bloc, Vector3i vec){
SetBlockAndRecompute(bloc, vec);
}[/code2]

Map.cs is required to build the scene/terrain thats why its in the scene view.
Thanks for the help!

Comments

  • I did some searching and it seems I need to add a custom type in the custom type script. I dont know how this works at all; so I tried to send BlockData and Vector3i as object[] and I still get cannot serialize BlockData?
  • Tobias
    Options
    What is the error you get when you try to register the BlockData?
    You sent a PM but I'm still pretty much clueless what your current issue is.
  • Ohiyx4
    Options
    I get a error "Cannot Serialize(): BlockData". As in the first post at first csharp code field.
    When I tried to pass BlockData() and Vector3i() as a object array (by storing them into object array and converting them to a object so it can be passed over the RPC, then converted back.), I still get the error code as in: "Cannot Serialize(): BlockData, Vector3i.
    I hope this clears things up for you.
  • Tobias
    Options
    BlockData and Vector3i are not known to Photon and so it can't transform these into the byte[] needed to send them via network.

    When you want to send a Vector3i(nteger), you could send 3 integers instead or a int[3]. Like RPC("rpcName", Vector3i.x, Vector3i.y, Vector3i.z).
    Alternatively you can register your own, custom data types in Photon. This allows you to send RPC("rpcName", vector3i). This is explained here:
    http://doc.exitgames.com/en/realtime/cu ... -in-photon