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 /
  • Help Room /
avatar image
0
Question by whatisthislol · Oct 19, 2020 at 09:05 AM · photonsynchronization

Sync data to different players

Hello! I have buttons in my masterclient an if the host presses that button, other players will see what button the host pressed. I tried PunRPC but it's not working. Does anyone know what to do? here is a partial of the script

I have this button

 public void GameObjectValue()
     {
    
             gameObjectVote = true; //bool
 
         button1.interactable = false;
        button2.interactable = false;
       
     }
 

and then this PunRPC

  [PunRPC]
     void SendGameObjectValue()
     {
         gameObjectValue.text = "Game1";
         gameObjectValue.SetActive(true);
     }


and then I set it in update to update the data everytime a new player enters the room

  void Update()
     {
        
 
         if (button1.interactable == false && button2.interactable == false)
         {
             photonView.RPC("SendGameObjectValue", RpcTarget.Others);
         }
 
     }



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
0

Answer by Captain_Pineapple · Oct 20, 2020 at 08:37 AM

man PUN really should rework their RPC tutorial.... i see so many people running into this same issue....


anyway...: First lets try to understand what an RPC is. It is a function that player A and B know of and that one player can call at the other players game instance.

So A can call SendGameObjectValue to be executed at player B. The only information that you currently send however is that this function is to be executed. You do not transmit any other data yet.

To change that you have to add arguments to that function. Lets assume you have a function

 void  SendGameObjectValue(bool value1, bool value2)
 {
       gameObject1.SetActive(value1);
       gameObject2.SetActive(value2);
 }

then that would be able to receive 2 boolean values and set those values to the active state of the local objects gameObject1 and gameObject2

Then you only have to add actual values to the RPC call:

 photonView.RPC("SendGameObjectValue", RpcTarget.Others, true, false);

This will then call SendGameObjectValue at all other players where this photonView is existent with the arguments value1= true and value2 = false

Comment
Add comment · Show 5 · 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 whatisthislol · Oct 20, 2020 at 09:30 AM 0
Share

Hello thank your responding. Do I still put it in the update function or on click button for the host? because when I did this void Update() { if (button1.interactable == false && button2.interactable == false) { photonView.RPC("SendGameObjectValue", RpcTarget.Others, true, false); } }

I get

NullReferenceException: Object reference not set to an instance of an object

Sorry I'm new to photon and some are really confusing. Thank you for your time

avatar image Captain_Pineapple whatisthislol · Oct 29, 2020 at 07:46 AM 0
Share

oh boy, sorry for reading this really late. In case you have not solved this yet: If you post errors please always add the code it references to. Otherwise this error can mean anything.

avatar image whatisthislol Captain_Pineapple · Oct 31, 2020 at 08:45 AM 0
Share

Hello its okay thank you for still responding. I was able to remove the error by removing the RPC in update function

Show more comments

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

215 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 synchronization on different devices failes 0 Answers

How do i get the two client's units to match up rather than be incorrect units? 1 Answer

Photon synchronization on different devices failes 0 Answers

How do you Sync Avatars that aren't being controlled over the Photon Unity Network so that everyone over the network sees the same thing? 1 Answer

How to sync child objects in Photon Network 1 Answer


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