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
1
Question by murkantilism · Aug 03, 2016 at 02:20 AM · notificationstwice

Method runs twice, but isn't called twice and isn't subscribed twice

Method foo() is running twice and messing things up - I have ruled out the following potential causes:

  • Multiple instances of the script in the scene (with the ref: search of the scene hierarchy)

  • Multiple subscriptions to the Notification Center post (this method subs in the Awake() function, throwing a debug next to it yields only 1 call).

  • The method that posts the Notification is only run once

  • The Notification is not posted in any other script (I combed over every single script using CTRL-F just to be sure)

  • Edit: Also ruled out it being caused by ExecuteInEditMode, which doesn't appear in any of the relevant scripts.

One detail regarding #3:

The Notification that foo() is observing is posted by method baz() which is called by OnTriggerEnter(). This was calling baz() multiple times upon collision, until I used a simple boolean switch to prevent that. The boolean gets reset on OnTriggerExit(), and using debugs I've confirmed that these are each occurring once, so I am confident that this is not the cause of foo() running twice.

I realize that folks may want to see the code itself, but I'm really looking for ideas on what I can try to rule out and investigate. Posting the code here could be messy so it might be easier to link to the relevant places on GitHub if anyone is interested.

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

Answer by murkantilism · Aug 03, 2016 at 05:08 AM

Resolved!

Basically I had two scripts attached to the same gameObject that both subscribed to the same Notification, so each time the NotificationCenter went through the list of things to notify it sent each of these two scripts two notifications.

Details available here.

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

50 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

Related Questions

CSharpNotificationCenter Posting Messages with data 4 Answers

Trigger notification permission popup on iOS again 1 Answer

Mobile Notifications Icons on Android. 1 Answer

1st Problem: OnLevelWasLoaded, method is getting called twice. 2nd: Loading PlayerPrefs 1 Answer

iOS push notifications via Parse.com 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