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 /
  • Help Room /
avatar image
1
Question by psteng · Mar 27, 2017 at 09:38 PM · multiplayervariablephotonrpc

Variables not updated in PUN RPC function

I'm still somewhat new to Unity and have been wrestling with this problem for a several days now. I am trying to send an array of values from the master client to any other client that joins using RPC functions. Basically, if the player is the Master client, createMaze is called and the value of rem_walls is set. I can see in the viewport when running the game that this is true. All other clients call the function createMaze2() which uses an RPC call to the Master to request the value for rem_walls, and the Master client sends this value back. However, for whatever reason, the value of rem_walls that is being sent is not the updated value of rem_walls. Hopefully the code below will make things more clear. Basically, in send_info() rem_walls is always empty, despite the fact that the variable has been updated and reflects this update when I check it in the viewport. Any help would be greatly appreciated.

     public void createMaze2(){
         //List<Vector3Int> to_rem;
         initMaze ();
         //PhotonView photonView = PhotonView.Get (this);
         if (!PhotonNetwork.isMasterClient) {
             this.photonView.RPC ("send_info", PhotonTargets.MasterClient, PhotonNetwork.player);
         }
     }
 
     [PunRPC]
     void send_info(PhotonPlayer plyr){
         if (PhotonNetwork.isMasterClient) {
             Debug.Log ("sending info");
             //PhotonView photonView = PhotonView.Get (this);
             Debug.Log (this.rem_walls);
             Debug.Log (this.rem_walls.Count);

             int[] ai = this.rem_walls.ToArray ();
             this.photonView.RPC ("get_info", plyr, ai);
         } else {
             Debug.Log ("something is wrong");
         }
     }
 
     [PunRPC]
     void get_info(int [] x){
         Debug.Log ("getting info");
         Debug.Log (x);
         rem_walls =new List<int>( x);
         Debug.Log (x.Length);
         for (int i = 0; i < x.Length; i=i+3) {
             Debug.Log (i);
             Destroy (Walls [x[i+2], x[i], x[i+1]].gameObject);
         }
     }
 
     public void createMaze () {
         rem_walls.Add(1);
     }
 
Comment
Add comment · Show 3
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 ChristianSimon · Mar 28, 2017 at 08:20 AM 0
Share

Hi,

can you confirm that rem_walls.Count is already up to date when send_info is being called? Since you already have a Debug.Log(...) call around it I guess you have already taken a look at that. Can you also confirm that int[] ai is properly set? Can please also describe what happens in init$$anonymous$$aze() function? Otherwise I currently don't see, why this is not working.

avatar image psteng ChristianSimon · Mar 28, 2017 at 03:09 PM 0
Share

Thanks for the response. rem_walls.Count is up to date when send_info is called because I looked at the variable in the editor as the game is run and it has the correct values. The Debug.Log(rem_walls.Count) however prints 0. As far as I can tell, ai is properly set. Though it shouldn't matter as I also tried doing this with just a single int rather than an array and it had the same issues. init$$anonymous$$aze() basically just instantiates a bunch of gameobjects in the scene for the map. I can't imagine it has anything to do with the RPC call issues.

avatar image ChristianSimon psteng · Apr 03, 2017 at 08:46 AM 0
Share

Can you maybe share this project stripped-down to its problems so that I can reproduce it because currently I am out of ideas what the problem might be.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Hsni · Dec 03, 2018 at 08:32 AM

I have same problem. Someone please help.

 public static int lvl = 0;
 bool isLocked = false;


 int temp = 0;

 // Use this for initialization
 void OnEnable () {
     if (!isLocked)
     {
         temp = Random.Range(0, 10);
        UnityEngine.Debug.Log(isLocked);
         GetComponent<PhotonView>().RPC("UpdateVariables", PhotonTargets.All);

     }

 }



 [PunRPC]
 void UpdateVariables()
 {
     lvl = temp;
     isLocked = true;
 }

 // Update is called once per frame
 void Update () {

      UnityEngine.Debug.Log(isLocked);
 }
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
avatar image
0

Answer by Moongale · Jan 24, 2019 at 12:18 PM

Hi dudes,

I have faced the same problem and realized that variables inside the [PunRPC] functions do not change, i solved my problem via using PhotonNetwork.RaiseEvent,

Good lucks

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

135 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

Related Questions

Help with photon being used to make a mulitplayer fps 0 Answers

Photon RPC 2 Answers

PhotonUnity player move object problem ! 1 Answer

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

Photon RPC Only Working Halfway 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