Author Topic: Removing event listeners  (Read 7214 times)

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Removing event listeners
« on: July 17, 2012, 05:19:33 PM »
Hi,

I'm wondering whether I need to remove event listeners when a scene has ended, typically I will put in a -= for events in the OnDisable method, but for NGUI events, should I do the same thing:

UIEventListener.Get(myButton).onClick -= UIButtonPressed;

or do these get removed by NGUI?

-JJ

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Removing event listeners
« Reply #1 on: July 17, 2012, 06:35:49 PM »
Does your UI persist when the scene unloads? Unless you mark your UI Root as "dont destroy on load", it'll be destroyed, so the removal of callbacks is unnecessary.

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Removing event listeners
« Reply #2 on: July 17, 2012, 06:37:09 PM »
Awesome thanks, yeah the UI does not persist so looks like I don't have to do anything :)

lbzzbl

  • Guest
Re: Removing event listeners
« Reply #3 on: July 18, 2012, 09:53:31 AM »
followup question:

if such a scenario occurs

currently in scene 1 -> load into scene 2 -> then back to scene 1 after some actions...essentially, scene 1 is my main scene which i will always return to, like a big lobby?

would it be better if i let the UI of scene 1 persists instead of letting it go away?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Removing event listeners
« Reply #4 on: July 18, 2012, 11:00:18 AM »
No need. It's better to let Unity release the unneeded resources.

lbzzbl

  • Guest
Re: Removing event listeners
« Reply #5 on: July 18, 2012, 12:16:46 PM »
thanks.