Author Topic: The object of type 'UIButton' has been destroyed  (Read 5335 times)

chiblue

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
The object of type 'UIButton' has been destroyed
« on: November 30, 2016, 04:49:50 PM »
I have a grid that I am adding a gameobject to in a loop,  this is basically a list of items in an inventory.  The gameobjects being added contain a UIButton script which calls a  onclick function attached to the gameobject.  I keep getting the same error whenever I click on any of the items in the grid... at this point onclick no long functions.

MissingReferenceException: The object of type 'UIButton' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

I populate the grid using the following code... inside a loop

  1.                        
  2. GameObject _item = Instantiate(MenuItem) as GameObject;
  3.  _item.name = _weap.ItemName;
  4. _item.transform.parent = _gridobject.transform;
  5. // outside loop
  6. gridControl.Reposition();
  7.  

The load function for the grid is called from the Awake() in a script on the parent object.  I tried placing the call in Start() thinking it was trying to establish the grid before all objects have been loaded... I use this technique on other lists without any issues...

chiblue

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: The object of type 'UIButton' has been destroyed - RESOLVED
« Reply #1 on: December 01, 2016, 05:52:30 AM »
I finally figured this out,  it was the result of not destroying the instance of a class and the panel load was seeing as an active instance and trying to create buttons on a destroyed panel.  My bad... but it was somewhat complex,  moral of the story... make sure you destroy your active objects correctly.