- Home /
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.
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612090048im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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