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 airbagnr1 · Mar 12, 2018 at 07:57 PM · networkingphotonbooleanevent

Photon player RaiseEvent sending bools

Hi there, I'm having issues sending my bool across the network and I'm using the RaiseEvent from photon and I'm not sure I really understand it and that's why it's not working. My scenario is: there are 4 players and once a player hits a button then they ready up and that's it but I can't seem to send the 'playerXactivated' bool across.

Here is my code, if someone can help me understand that would be great!:)

 #region Testing Variables
     byte eventCode = 0;
     bool reliable = true;
 
     #endregion
 
     #region Testing Methods
     void OnEnable()
     {
         PhotonNetwork.OnEventCall += this.OnEvent;
     }
     void OnDisable()
     {
         PhotonNetwork.OnEventCall -= this.OnEvent;
     }
 
     private void OnEvent(byte _eventCode, object content, int senderid)
     {
         if(_eventCode == 0)
         {
             PhotonPlayer sender = PhotonPlayer.Find(senderid);
             byte[] test = content as byte[];
             for (int i = 0; i < test.Length; i++)
             {
                 byte unitId = test[i];
             }
         }
     }
     #endregion
 
     #region Public Methods
     public void ThiefCollectionButton()
     {
         PhotonNetwork.RaiseEvent(eventCode, player1Activated = true, reliable, null);
         canvasObj.SetActive(false);
     }

Thanks again!

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
Best Answer

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

Hi,

the problem is that you are sending just a boolean value but trying to cast it to an array of bytes in the OnEvent function, which obviously won't work at all. So in order to make this work you would have to do something like bool test = (bool) content;.

However instead of using RaiseEvent in this case, I would recommend you using the Custom Player Properties. Whenever a client presses a certain button, he can use his Player Properties to let each other client know, that he is ready. This can be done by using the following code snippet for example:

 ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable() { { "PlayerIsReady", true } };
 PhotonNetwork.player.SetCustomProperties(properties);

Whenever a client set his Player Properties, those are automatically updated on each other client as well. The client is notified about this when the callback void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps) is called. You can see how this callbacks works here.

The MasterClient can use this callback and iterates through the player list in order to see if all clients are ready (if you want this scenario).

Comment
Add comment · Show 2 · 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 airbagnr1 · Mar 13, 2018 at 01:34 PM 0
Share

Hi Simon, thanks for the reply much appreciated! However, I'm still having a little bit of an issue. I have tried using the custom player properties but still not sure on where I'm going wrong. Currently when a player hits the button to ready up then the bool is only activated on them and not send to the other players... Here is my code: So my start function looks like this:

         properties.Add("Player1Ready", player1Activated);
         properties.Add("Player2Ready", player2Activated);
         properties.Add("Player3Ready", player3Activated);
         properties.Add("Player4Ready", player4Activated);
         PhotonNetwork.player.SetCustomProperties(properties);

And then when a player hits their button to ready up I do this:

         PhotonNetwork.player.CustomProperties["Player1Ready"] = true;
         PhotonNetwork.player.SetCustomProperties(properties);

Finally in the update statement im just checking if the bool has been activated then doing something. I had put the code in the OnPhotonPlayerPropertiesChanged method but that didnt seem to work as well...

    if (player1Activated)
         {
             print("player1 active");
             player1Button.SetActive(false);
         }


Thanks again!

avatar image ChristianSimon airbagnr1 · Mar 13, 2018 at 02:53 PM 0
Share

Don't modify Properties directly. Please use the given function for modifications ins$$anonymous$$d, to make sure, that those properties are synchronized correctly with all clients.

Another hint: use the callback to check for modified properties. This is much more efficient than checking this each time Unity's Update function runs. You also only have to do this on the $$anonymous$$asterClient, as he is the one to start the game, unless you want to show the state to all clients.

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

118 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

Related Questions

[Photon]Player vs. Player Collision 0 Answers

how do i apply damage to objects other that the player 1 Answer

Photon - character not moving after next Scene Load 0 Answers

Bolt Engine or Photon Server? 0 Answers

Using Photon network to sync interactions between players 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