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 /
avatar image
0
Question by tommi27 · Jan 31, 2015 at 04:28 PM · multiplayerclientclient-server

Send RPCs on application quit

Hi,

I have a problem with RPC, when i try to send an RPC while i quit my application RPC are don't called, how can i fix it?

Comment
Add comment · Show 5
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 meat5000 ♦ · Jan 31, 2015 at 03:08 AM 1
Share

Got some code?

avatar image tommi27 · Jan 31, 2015 at 09:32 AM 0
Share
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class TestScene : Photon.$$anonymous$$onoBehaviour {
 
     List<string> chat$$anonymous$$essages;
     int maxChat$$anonymous$$essages = 5;
 
     void OnApplicationQuit() {
         AddChat$$anonymous$$essage (PhotonNetwork.player.name + " è uscito");
     }
 
     public void AddChat$$anonymous$$essage(string m) {
         photonView.RPC ("AddChat$$anonymous$$essage_RPC", PhotonTargets.AllBuffered, m);
     }
     
     [RPC]
     void AddChat$$anonymous$$essage_RPC(string m) {
         while(chat$$anonymous$$essages.Count >= maxChat$$anonymous$$essages) {
             chat$$anonymous$$essages.RemoveAt(0);
         }
         chat$$anonymous$$essages.Add(m);
     }
 
     
 }

this is my code and in void "OnApplicationQuit" i try to call RPC but it doesn't work

avatar image ExtremePowers · Jan 31, 2015 at 04:35 PM 1
Share

Would it be smarter to do this in OnPlayerDisconnected? I am not sure if phonton has that feature though.

avatar image tommi27 · Feb 01, 2015 at 01:57 AM 0
Share

I tried but doesn't work.. How can i view a message to the user, like: "Are you sure to exit?"

avatar image Josh707 · Feb 01, 2015 at 09:02 AM 0
Share

The application might not be given enough time to send out the RPC before it gets closed, they might not be sent the instant RPC() is called. Or perhaps Photon catches OnApplicationQuit first and disconnects you before. I'm not sure what you tried but Photon does have the OnPhotonPlayerDisconnected(PhotonPlayer) message.

As for that quit message, you would have to set it up in your in-game GUI menus.

1 Reply

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

Answer by tobiass · Feb 02, 2015 at 12:30 PM

Sending of the RPC fails, because it does not get sent immediately when you call it. RPC's are sent in intervals (like other messages) by default. This allows us to aggregate some messages.

Your code creates a message that would be send in the next interval but that doesn't happen anymore (due to app quit).

PUN should call PhotonNetwork.Disconnect() in it's own OnApplicationQuit() implementation. This a) will attempt to send immediately and b) tells the server that you are closing the app, too. The connection will be closed and the others get an update, too!

You can implement:

 void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer)
 {
   // AddChatMessage (otherPlayer.name + " è uscito");
 }
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 tommi27 · Feb 02, 2015 at 05:36 PM 0
Share

Yes, thank you it works!

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Time problem with Joining to Multilayer game 1 Answer

How to get the Host's player position ? 0 Answers

How to test Unity's new networking layer in separate game instances? 0 Answers

LLAPI Multiplayer - Client FPS very low when builded. 0 Answers

Can I create a separate server and use the Unity game objects in it? 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