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 /
  • Help Room /
avatar image
0
Question by Barsonax · Feb 13, 2016 at 09:43 PM · missingreferenceexceptioncustomeditordestroyimmediate

Weird MissingReferenceException

Iam getting a weird error that i cannot figure out;

The error MissingReferenceException: The object of type 'RUI_ArrayButton' 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. RUI_ArrayButton.ChangeImage (UnityEngine.Texture2D _newimage) (at Assets/Resources/RUI/Scripts/RUI_ArrayButton.cs:17) RUI_TabController.RefreshSprite () (at Assets/Resources/RUI/Scripts/RUI_TabController.cs:88) RUI_TabController.RefreshTabamount () (at Assets/Resources/RUI/Scripts/RUI_TabController.cs:137) RUI_TabEditor.TabamountEditor (.RUI_TabController _tabcontroller) (at Assets/Scripts/Editor/RUI/RUI_TabEditor.cs:65) RUI_TabEditor.OnInspectorGUI () (at Assets/Scripts/Editor/RUI/RUI_TabEditor.cs:20)

When does this happen? When i decrease the tabamount by any amount it throws this error. Other than this error everything seems to be working fine but i dont think unity throws this error for nothing.

The code thats causing this error:

     public void ChangeImage(Texture2D _newimage){
         if (ButtonImage == null) {
             Debug.Log (gameObject);
             ButtonImage = gameObject.GetComponent<RawImage> ();
         }
         ButtonImage.texture = _newimage;
         gameObject.GetComponent<RectTransform> ().sizeDelta = new Vector2 (_newimage.width, _newimage.height);
     }

Some more code (RUI_TabController class)

     public void RefreshTabamount(){
         if (Tabobjects.Length != Tabamount) {
             RefreshCheck ();
             if (Tabobjects.Length > Tabamount) {
                 int AmountToDestroy = Tabobjects.Length - Tabamount;
                 for (int i = 0; i < AmountToDestroy; i++) {
                     DestroyImmediate (Tabobjects [i]);
                 }
                 Tabobjects = gameObject.GetAllChildren ();
             }
             if (Tabobjects.Length < Tabamount) {
                 int AmountToInstantiate = Tabamount - Tabobjects.Length;
                 for (int i = 0; i < AmountToInstantiate; i++) {
                     GameObject tab = new GameObject ();
                     GameObject text = new GameObject ();
 
                     tab.transform.SetParent (gameObject.transform);
                     text.transform.SetParent (tab.transform);
 
                     tab.name = "Tab" + i;
                     text.name = "Text";
 
                     tab.AddComponent<RUI_ArrayButton> ();
                     Text tabtext = text.AddComponent<Text> ();
                     tabtext.raycastTarget = false;
 
                     RectTransform tabrect = tab.GetComponent<RectTransform> ();
                     tabrect.localScale = new Vector3 (1, 1, 1);
                     tabrect.anchorMax = new Vector2 (0, 0);
                     tabrect.anchorMin = new Vector2 (0, 0);
 
                     RectTransform textrect = text.GetComponent<RectTransform> ();
                     textrect.anchoredPosition = new Vector2 (0.0f, -0.75f);
                 }
                 Tabobjects = null;
                 Tabobjects = gameObject.GetAllChildren ();
                 RA = null;
                 RA = new RUI_ArrayButton[Tabobjects.Length];
                 for (int i = 0; i < Tabobjects.Length; i++) {
                     RA [i] = Tabobjects [i].GetComponent<RUI_ArrayButton> ();
                 }
             }
             RefreshSpacing ();
             RefreshText ();
             RefreshSprite ();
         }
     }

More code (the custom editor function that is called from the OnInspectorGUI method)

     private void TabamountEditor(RUI_TabController _tabcontroller){
         GUILayout.BeginHorizontal ();
         EditorGUILayout.LabelField ("Tabs",GUILayout.Width (60));
         EditorGUI.BeginChangeCheck();
         _tabcontroller.Tabamount = EditorGUILayout.IntSlider (_tabcontroller.Tabamount,1,100, GUILayout.Width (200));
 
         GUILayout.EndHorizontal ();
         if (EditorGUI.EndChangeCheck ()) {
             _tabcontroller.RefreshTabamount ();
         }
     }
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

0 Replies

· Add your reply
  • Sort: 

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

33 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

Related Questions

Destroying GameObject while in Inspector = MissingReferenceException 0 Answers

Unity error The object of type 'Preview' has been destroyed but you are still trying to access it. 0 Answers

MissingReferenceException: The object of type 'Animator' has been destroyed but you are still trying to access it. 4 Answers

Help Simple adding a GameObject to an ObjectField() 1 Answer

The referenced script on this Behaviour (Game Object 'FirstPersonCharacter') is missing! 1 Answer


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