Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Chizukoo · Sep 25, 2019 at 08:21 AM · networkingphotonvuforiasyncmarker

Photon only shows host their changes to players, not other way around

I'm trying out photon for the first time. I work with vuforia and a marker. A cube spawns on the marker and you can move it with a canvas button.

Whenever the host clicks the button, the other player can also see the changes. But when the player clicks the button it moves for a second and then goes back. At my host their screen you can't see any movement done by the player.

Are there good tutorials to simply sync changes with photon? (it's on android)

Here's a simple script to try it out, which I'm using atm:

  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using Photon.Pun;
  
  public class Change : MonoBehaviour, IPunObservable
  {
      public void buttonpress()
      {
          transform.position = new Vector3(transform.position.x, transform.position.y + .5f, transform.position.z);
      }
  
      public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
      {
          if (stream.IsWriting)
          {
              stream.SendNext(transform.position);
          }
          else if (stream.IsReading)
          {
              transform.position = (Vector3)stream.ReceiveNext();
          }
      }
  }
Comment
Add comment
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
1

Answer by Captain_Pineapple · Sep 25, 2019 at 03:45 PM

Hey there,

to work with networking and photon in specific you have to understand a basic principal of synchronization: It always happens in one direction by default!


Think about it like this. If Client A and B were to move the cube at the same time to a new position, whose position would be the "true" position? One has to be discarded to make sure that you do not drop out of sync. But who decides to do this?


For this reason you have the photonview with its stream. The stream has a sending side (where you have stream.IsWriting and a receiving side with stream.IsReading. This way you make sure the sendings position is always the true position. This implies though, that you can NOT modifie the position of the cube directly on the receivers side, because every 1/10 second when an update arrives, the position will be reset to the position you sent from the senders side. (which is what you described to be your observations)


So how to fix this:

What you need is some additional update method. Easiest way: Use an RPC which sends a relative position change to the objects owner/sender. For the usage of RPCs photon provides a simple documentation. It does not go too far into detail but should be good enough for your problem. RPC Documentation

Note at this point that each RPC might end up as an additional message so do not generate RPCs each Update.

In general your code has to change into something like this:

 public void buttonpress()
     {
         Vector3 change = new Vector3(0, 0.5f, 0);
         //check if we are the owner/sender on this object:
         if (photonView.IsMine)
         {
             transform.position += change;
         }
         else
         {
             photonView.RPC("posChangeRPC", photonView.Owner, change);
         }
     }
 
     [PunRPC]
     public void posChangeRPC(Vector3 posChange)
     {
         transform.position += posChange;
     }

Not tested and only spent half a though on this so you might have to tweak it here and there!

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

167 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

Related Questions

Photon only host changes sync 0 Answers

Syncing FPS Firing Sound over network via RPC {PHOTON} 1 Answer

[PUN] Syncing Rigidbodies across network. 1 Answer

RPC with Random Numbers! 2 Answers

Unity Editor Crash !!! 0 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