Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Piripant · May 26, 2014 at 08:32 PM · errorphotonsynchronization

Photonview.RPC Error

In the last days I was trying to make a first person game where you can drive vehicles. When i was trying to syncronize the helicopter movements i found that photonView.RPC was the best method. But, when i started to make my experiments i always got a lots of errors. The one that i found as main is this:

Exception: cannot serialize(): UnityEngine.Transform 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, Boolean encrypt) LoadbalancingPeer.OpRaiseEvent (Byte eventCode, System.Object customEventContent, Boolean sendReliable, .RaiseEventOptions raiseEventOptions) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/LoadbalancingPeer.cs:496) NetworkingPeer.OpRaiseEvent (Byte eventCode, System.Object customEventContent, Boolean sendReliable, .RaiseEventOptions raiseEventOptions) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:925) NetworkingPeer.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2797) PhotonNetwork.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2409) PhotonView.RPC (System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:257) Move.OnCollisionEnter (UnityEngine.Collision collider) (at Assets/Scripts/Player/Move.cs:135)

And there are other similar erros in other part of code where i try to call RPCs. This is my main script:

 using UnityEngine;
 using System.Collections;
 
 public class Move : Photon.MonoBehaviour {
 
     float VerSpeed;
     float HorSpeed;
     float VerSpeedHel;
     float HorSpeedHel;
     Vector3 realPosition = Vector3.zero;
     Quaternion realRotation = Quaternion.identity;
     public bool driving = false;
     Rigidbody Heli;
     Fall fallscript;
     PhotonView Heliview;
     GameObject Seat;
     Vector3 fwdrot = new Vector3(0,0, -10);
     Vector3 backrot = new Vector3(0,0, 10);
 
     // Use this for initialization
     void Start () {
         if (photonView.isMine) {
             PhotonNetwork.player.name = Random.Range(0,9999).ToString();
             Debug.Log("Player name: " +PhotonNetwork.player);
         }
 
         else {
             Destroy(rigidbody);
         }
     }
     
     // Update is called once per frame
     void Update () {
         if(photonView.isMine) {
             if (!driving) {
                 VerSpeed = Input.GetAxis("Vertical") * Time.deltaTime * 10;
                 HorSpeed = Input.GetAxis("Horizontal") * Time.deltaTime * 10;
                 transform.Translate(HorSpeed,0,VerSpeed);
             }
 
             else {
 
                 if (Input.GetKey(KeyCode.W)) {
                     photonView.RPC("MoveFwd", PhotonTargets.MasterClient);
                 }
 
                 if (Input.GetKey(KeyCode.S)) {
                     photonView.RPC("MoveBack", PhotonTargets.MasterClient);
                 }
 
                 if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S)) {
                     photonView.RPC("Stop", PhotonTargets.MasterClient);
                 }
 
                 if (Input.GetKey(KeyCode.Q)) {
                     photonView.RPC("rot", PhotonTargets.MasterClient, new Vector3(0,-100,0));
                 }
 
                 if (Input.GetKey(KeyCode.E)) {
                     photonView.RPC("rot", PhotonTargets.MasterClient, new Vector3(0,100,0));
                 }
 
                 if (transform.position.y < 75) {
 
                     photonView.RPC("Up", PhotonTargets.MasterClient);
 
                     if (Input.GetKey(KeyCode.Space)) {
                         photonView.RPC("Force", PhotonTargets.MasterClient, new Vector3(0,70,0));
                     }
                 }
 
                 if (Input.GetKey(KeyCode.LeftShift)) {
                     photonView.RPC("Force", PhotonTargets.MasterClient, new Vector3(0,-70,0));
                 }
 
                 if (Input.GetKey(KeyCode.Escape)) {
                     transform.localPosition = new Vector3(0.3319414f,0.07f,2f);
                     gameObject.AddComponent<Rigidbody>();
                     rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
                     gameObject.GetComponent<BoxCollider>().enabled = true;
                     fallscript = gameObject.GetComponent<Fall>();
                     fallscript.enabled = true;
                     Seat.tag = "EliSeat";
                     transform.parent = null;
                     driving = false;
                 }
             }
         }
 
         else {
             this.gameObject.transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
             this.gameObject.transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
         }
     }
 
     [RPC]
     public void rot (Vector3 force) {
         transform.parent.parent.GetComponent<Rigidbody>().AddTorque(force);
     }
 
     [RPC]
     public void MoveFwd () {
         transform.parent.parent.transform.rotation = Quaternion.Slerp(Heli.rotation, Quaternion.Euler(0, Heli.rotation.eulerAngles.y,-15), 3);
     }
 
     [RPC]
     public void MoveBack () {
         transform.parent.parent.transform.rotation = Quaternion.Slerp(Heli.rotation, Quaternion.Euler(0, Heli.rotation.eulerAngles.y,15), 3);
     }
 
     [RPC]
     public void Up () {
         transform.parent.parent.GetComponent<Rigidbody>().AddRelativeForce(0,8.81f,0, ForceMode.Acceleration);
         Debug.Log("Quack");
     }
 
     [RPC]
     public void Force(Vector3 force) {
         transform.parent.parent.GetComponent<Rigidbody>().AddRelativeForce(force);
          Debug.Log("Puff");
     }
 
     [RPC]
     public void Stop () {
         transform.parent.parent.transform.rotation = Quaternion.Slerp(Heli.rotation, Quaternion.Euler(0, Heli.rotation.eulerAngles.y, 0), 3);
     }
 
     [RPC]
     public void SetChild (Transform parent) {
         transform.parent = parent;
     }
 
     void OnCollisionEnter (Collision collider) {
         if(collider.gameObject.tag == "EliSeat") {
             photonView.RPC("SetChild", PhotonTargets.All, collider.transform);
             fallscript = gameObject.GetComponent<Fall>();
             fallscript.enabled = false;
             Destroy(rigidbody);
             gameObject.GetComponent<BoxCollider>().enabled = false;
             Heliview = transform.parent.parent.gameObject.GetComponent<PhotonView>();
             collider.gameObject.tag = "Busy";
             Seat = collider.gameObject;
             driving = true;
             transform.localPosition = new Vector3(0.3319414f,0.0289368f,-2f);
             transform.localEulerAngles = new Vector3(0,180,90);
         }
     }
 
     public void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info) {
         if(stream.isWriting) {
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
         }
         
         else {
             realPosition = (Vector3)stream.ReceiveNext();
             realRotation = (Quaternion)stream.ReceiveNext();
         }
     }
 }

Sorry if my English is not the best.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image siaran · May 26, 2014 at 08:48 PM 0
Share

I'm not sure what causes your error but you do NOT want to send RPCs every frame that a button is pressed, that is going to cause a lot of lagging in your game. just send and receive that information in the OnPhotonSerializeView method.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tobiass · Jun 12, 2014 at 09:00 AM

The error says it all: "Exception: cannot serialize(): UnityEngine.Transform"

Transforms can't be sent, because the Engine doesn't allow us to instantiate them. You have to send the individual components pos, rot and or scale instead and apply them to some target transform.

RPCs are called via some PhotonView. This is a component of some GameObject. The other clients will execute the called method only on the corresponding GameObject in their client. Due to that, you don't have to send a parent in most cases.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Photon RPC "DestroyRpc" function not found 1 Answer

Photonview with 4 separate cameras 0 Answers

operation failed: OperationResponse 253: Return Code -2 (Actors exceeds currentPlayersCount) Parameters: {}Server:GameServer 0 Answers

Synchronization in Photon, I have a scene where I dont instantiate anything, but I want it to update its status constantly on all clients 1 Answer

converting Photon stream to JS 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges