• 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 /
  • Help Room /
avatar image
Question by Oattjv · Mar 11, 2018 at 05:13 PM · multiplayerphotonrpcpun

PhotonUnity player move object problem !

Hey, sorry for my bad english. here's my problem.... now I'm try to make Multiplayer Stuff with Photon Unity network right now, I can spawn a player and each player can't see each other next I'm try to let the player instantiate a Cube from the scripts ( not a prefab ) and move them [PunRPC] public void CreateObj(int objID) { id1 = PhotonNetwork.AllocateViewID(); if (objID == 1) { sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere); sphere.AddComponent<PhotonView> (); sphere.AddComponent<NetworkCharacter> (); PhotonView pv = sphere.GetComponent<PhotonView> (); pv.synchronization = ViewSynchronization.UnreliableOnChange; pv.ObservedComponents = new List<Component>(); pv.ObservedComponents.Add(sphere.GetComponent<NetworkCharacter> ());

the problem is each player can Move them BUT each player can see another player's object movement which mean the Object that have been spawn remain the same position in another player screen

I tried to do few things and i assume that I have to used 2 method which is RPCs to send a new Position of that object look like this

 [PunRPC]
         void OnGizmo(int selectID, float AmountToMove)        
         {
 
             Debug.Log (selectID +","+AmountToMove );
             target.transform.Translate (axis * AmountToMove, Space.World);
 //            PhotonView.Find(selectID).transform.Translate (axis * moveAmount, Space.World);
             PhotonView.Find(selectID).transform.position = new Vector3(target.transform.position.x,target.transform.position.y,target.transform.position.z);
 
         
         }

and another method by 'void OnPhotonSerializeView'

 void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info)
     {
         Debug.Log ("isStream");
         if (stream.isWriting) {
             Debug.Log ("isWriting");    
             stream.SendNext (transform.position);
             stream.SendNext (transform.rotation);
 
 
 
 
         } else {
             Debug.Log ("isReading");
             FirstPosition = (Vector3)stream.ReceiveNext ();
             realRotation = (Quaternion)stream.ReceiveNext ();
         }
     }

which I already attached to Observe Components list BUT stream.isWriting are not firing after I tried to Debug it and I don't sure why this happen and how to fix it,

Anyone have any suggestion PLEASE let me know I really need you guys, THANKS!

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by ChristianSimon · Mar 13, 2018 at 10:29 AM

Hi,

I don't know if this already solves the problem but in your CreateObj function you are calling id1 = PhotonNetwork.AllocateViewID();. Since this is marked as [PunRPC] I assume that each client calls this line which is not the correct way of doing it because each client will allocate a different ViewId this way. If you want to use Manual Instantiation, I would recommend you taking a look at the Manual Instantiation section (bottom of the page) of the this documentation page.

Besides that in your OnPhotonSerializeView function the receiver just stores received information in local variables 'FirstPosition' and 'RealRotation'. If you update the object's transform component anywhere else in your code, it's fine. If you don't update it, you have to do it somewhere in your code.

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

188 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 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 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 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 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 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 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 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 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

How do i use RPC's to set a object active in the hierarchy for all Players in the room and also how do i synchronize UI events focused on a VideoPlayer (Play, Pause etc.)) 0 Answers

Updating enemy AI in Photon PUN2 0 Answers

(photon) weapon switch event is not visible for others (tried rpc) 0 Answers

Unity3D photon. bool resets. 0 Answers

Variables not updated in PUN RPC function 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