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 cooltrophygameing · May 15, 2019 at 04:07 AM · photonmultiplayer-networkingsynchronization

Photon Int sync not working

I feel very stupid for asking this but I've turned despite. So im trying to get a int to show how many people escaped something. Whenever a player collides with the escape place it shows up you escaped and "int + out of 4 people escaped. But it won't sync the int. By the way im using photon Pun 2. Here is the script.`public class c : MonoBehaviour, Photon.Pun.IPunObservable { public Text text; private int escaped; public PhotonView photonView;

 void Start () {
   
     
     
 }
 public void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.name == "bobbobbob(Clone)")
     {

         escaped++;
     }
 }
 // Update is called once per frame
 void Update()
 {
     text.text = escaped + " out of 4 escaped alive";

     
 }
 
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.IsWriting)
     {
         stream.SendNext(escaped);

     }

     if (stream.IsReading)
     {
         escaped = (int)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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Captain_Pineapple · May 15, 2019 at 02:08 PM

Yo,

this is the same problem as in your last 2 questions... Please learn 2 things:

1: Do not sync things that do not change every frame by using the stream! Use an RPC for that. This will also solve your problem on it's own when you change to using an rpc.

2: When you use the stream. There will be one "true" variable that everyone else will follow... When A owns the "escape" thing then only the collision on player A's instance will do anything. For some player B,C,... they will change the variable and then recieve the synchronized value form player A who owns the object and overwrite the value.

Think about ownership of object instances. Let me know if something was unclear, you basically had this same problem the third time now. Look into this question you posted. Its exaclty the same issue.

Comment
Add comment · Show 7 · 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
avatar image cooltrophygameing · May 17, 2019 at 01:55 AM 0
Share

It worked thanks. But for some reason the other players can't see the master client.

avatar image Captain_Pineapple cooltrophygameing · May 17, 2019 at 07:24 AM 0
Share

Can you elaborate what you mean by "can't see"? They do not get the "escape" of the master client?

avatar image cooltrophygameing · May 17, 2019 at 08:45 PM 0
Share

What im trying to say is that when they spawn they literally can't see the master client player on their screen they can just go right through where the master client player is.

avatar image Captain_Pineapple cooltrophygameing · May 18, 2019 at 09:30 AM 0
Share

Did you make sure that the master clients player is created by PhotonNetwork.Instantiate and did you make sure that you are connected to a room before you do that?

avatar image cooltrophygameing · May 18, 2019 at 06:47 PM 0
Share

Yes everything is working the master client can see all the other players but they can't see him here is my spawn script for when they spawn.

 private void OnLevelWasLoaded(int level)
     {
         if (level == 1)
         {
             PhotonNetwork.Instantiate(Path.Combine("player", "bobbobbob"), new Vector3(0, 0, 0), Quaternion.identity, 0);
         }
 
 
 
         
            
            
         
 
 
 
     }
avatar image Captain_Pineapple cooltrophygameing · May 19, 2019 at 08:53 AM 0
Share

2 things: OnLevelWasLoaded is deprecated and this does not mean that you are connected to a room. Only instatiate netowrked objects if PhotonNetwork.InRoom is true. This way you can make sure that photon will recognize the instantiation of your object.


The LevelLoad can be completed before the room was joined. There is also a callback named OnJoinedRoom that could be used for you here.

So every player could instatiate his own player char when the room was joined.

You can check out the documentation on callbacks here. (assu$$anonymous$$g you use photon2)

avatar image cooltrophygameing Captain_Pineapple · May 19, 2019 at 04:46 PM 0
Share

A few things. In my game. There is a lobby scene and a game scene. The problem with OnJoinedRoom is that they join the room in the lobby scene. In the lobby scene, when it reaches four players it starts a countdown which transfers all the players to the game scene. I tried photonNetwork.InRoom in my void start but I still got the same results.

avatar image
0

Answer by cooltrophygameing · May 16, 2019 at 08:19 AM

Hey,

First I just want to say sorry for asking a lot of questions. Second, before I asked this question, I used a RPC but it didn't work here is the script where I used the RPC. alt text

I double checked everything but it still said 0 thats why I went back to using the stream.


screenshot-76.png (30.6 kB)
Comment
Add comment · Show 1 · 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
avatar image Captain_Pineapple · May 16, 2019 at 02:41 PM 1
Share

Did you try to debug your rpc code? i guess not.

If you add a Debug.Log in your ecapefun()you will realize that it is never called.

First: Add the [PunRPC] description to the ecapefun()

Secondly and most important: Do not blindly copy code without thinking about it. Think about what the parameter falsein your rpc call does. It had some "use" in the case of the door but here it's useless. If you look at the ecapefun there is no parameter to pass.

So either add a boolean parameter to the function if you need that or remove the parameter from the rpc call.

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

113 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

Related Questions

Syncing random player colors through PUN2 1 Answer

Photon Unity Networking (Viking Demo) Error: Argument is out of range. 1 Answer

multiplayer variable synchronization problem 1 Answer

sync objects over photon network 0 Answers

Photon Network syncing the transform of a moving platform 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