• 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 garrilla · Jan 12, 2016 at 09:05 PM · execution orderstoppingosc

help with events on stop playmode - send OSC message on stop

Hi

My session has some interaction with an external service via OSC.

I have it working well:

  • initiating the OSC client on Awake()

  • using Start() and Update() in scripts on Game Objects to send OSC events

but I'm struggling to find a solution to send a final OSC message when the game stops - user clicks playmode to stop - using OnApplicationQuit()

The OSC client appears to get destroyed before I can send the OSC messages, however that is intermittent - some times the code runs before the client is destroyed.

So I know I need to send these OSC messages slightly earlier but I can't see where - I've read the manual for Execution Order http://docs.unity3d.com/Manual/ExecutionOrder.html and couldn't work anything out for myself.

I'm not sure how I can better handle this end of lifecycle event. If Anyone has any suggestions I'd be grateful for any hints.

Here's my code:

 public class initOSC : MonoBehaviour {
     
     // when the world is awake, get the OSC ready
     void Awake()
     {
         OSCHandler.Instance.Init();
     }
 
     // called when the game is stopping   --- OnApplicationQuit
     void OnApplicationQuit()
     {
         Debug.Log("stopping");
 
         // get external sources 'parent' object
         var externalSrcs = GameObject.Find("External Sources");
 
         // for each child sound source, 
         foreach (Transform child in externalSrcs.transform)
         {
             var client = "target",
                    address= "/" + child.name + "_player" + "/" + ""
                    data = 0; //stop
             OSCHandler.Instance.SendMessageToClient(client, address, data);
         }
     }
 }

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

37 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

Related Questions

How to play audio when Time.timeScale =0 ? (see picture) 0 Answers

Script not executing in Android build but working in Editor 1 Answer

Stopping sliding on ground in underwater scene 0 Answers

Why does Unity stop responding on pressing Play? 0 Answers

Ensuring script execution order with Awake() 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