Author Topic: UICamera events are referencing objects in previously loaded scene.  (Read 2074 times)

Sermolux

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Hi,

I'm having an issue using UICamera.onClick as a catch all. When I first start the app it behaves as expected, but when I load a new scene I get a MissingReferenceException. I believe that the onClick event is still looking for the object in the previous scene. This happens for all events through UICamera. I find that if I set UICamera.onClick to null just before I load a scene everything works. Am I using this incorrectly?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You need to register it in the script's OnEnable, and unregister in OnDisable. I'm guessing you don't do the unregistration part, so yes of course you get an exception.