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 JB2019 · Aug 24, 2020 at 11:00 AM · coroutinethreadsevent-handling

Why does my EventHandler listener method not finish execution?

I have integrated Firebase Database into my Unity project. I have a FirebaseInit script and a FriendManager script. I've set up a UnityEvent to be invoked once the Firebase "CheckAndFixDependenciesAsync" is completed and I've set up my Firebase database reference. This event that is invoked triggers a listener in my FriendManager that then initializes a friendslist using the Firebase Database reference.

Here's the problem: In the method that is triggered in my FriendManager class when the event is invoked ("HandleFriendManagerInit"), I see a Debug.Log call that tells me the code is being executed. But then I have further calls as the code executes that never get called. And, the code that should execute (ie: get the friendslist from Firebase and use it to populate a DropDown UI element) doesn't execute.

Question: is there something with threading model in Unity that could cause the eventhandler method being triggered by the listener to start execution but never finish?

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
1

Answer by JB2019 · Aug 25, 2020 at 03:15 AM

Update to the above - I did some deeper debugging and discovered the thread was hitting some kind of exception that killed the thread. It was caused by references to GameObject.Find and .GetComponent<...>()... I ended up removing those calls from my EventHandling function and now the method completes properly.

NEW Question is - why would references to GameObject.Find or .GetComponent cause an exception to be hit that would kill that thread?

Comment
Add comment · Show 3 · 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 stevencr4z · Oct 19, 2020 at 04:56 PM 0
Share

Thank you! Solved my problem immediately. Just for future debugging, can I ask how you figured that out? Like what tools you used?

avatar image unity_ek98vnTRplGj8Q · Oct 19, 2020 at 05:22 PM 0
Share

To answer @JB2019 's question, Unit is **not** thread safe, meaning that using Unity's API is only allowed from the main thread. There are things that you can do to get multithreaded programs working, but they all involve offloading all API calls to the main thread.


avatar image JB2019 · Oct 20, 2020 at 03:24 AM 0
Share

@stevencr4z - I use Visual Studio Code alongside Unity and set up debugging (set VS Code as. your external script editor in Unity>Preferences, and download the Debugger for Unity extension in VS Code). Pretty helpful!

@unity_ek98vnTRplGj8Q - thanks for the response and yes, I've since had to move certain calls back to main thread execution to work.

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

142 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

Related Questions

Coroutine Death on Scene Change 3 Answers

How to handle a slow function from a dll 1 Answer

Return value from coroutine to non monobehaviour 1 Answer

Instantiating many objects during update lags 1 Answer

Coroutine - events not working 2 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