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 TommyHansenKiloo · Sep 15, 2016 at 08:55 AM · editoreditor-scriptingselectioneditor scriptingdependencies

Editor tool for selecting inverse dependencies, no-longer works in Unity 5.4?

Hey guys So for cleaning up in our project I wrote an editor tool that can select "inverse dependencies" (call them dependants or dependees) of an object... It works by first collecting all assets of the project, then going over them and checking their dependencies against the selected object. This gives you a collection of objects that depend on the selected asset, and if that collection is empty, the assumption is that the selected object can be safely removed from the project, as it is no longer referenced/used. My problem now is that after upgrading to Unity 5.4, the tool no-longer works... It will result in a weird editor error, where all text disappears and the editor has to be restarted... like so: alt text

Here is the code for the tool:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEditor;
 using System.Linq;
 
 public class SelectDependants : Editor
 {
     private static bool _checking;
     private static float _progress;
     private static string _status;
     private static Object selectedObject;
     private static Object[] selectedObjects = new Object[]{};
     private static string[] allAssetPaths = new string[]{}; 
     private static List<Object> allObjects = new List<Object>();
 
     [MenuItem("Assets/Select Dependants")]
     private static void FindDependants()
     {
         // Get selected object
         //selectedObject = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(Selection.activeInstanceID), typeof(Object));
         selectedObjects = Selection.objects;
 
         // Gather all objects
         allAssetPaths = AssetDatabase.GetAllAssetPaths();
 
         //Progress bar info
         _checking = true;
         _progress = 0f;
         _status = "Collecting all assets...";
         int iterator = 0;
         int listSize = allAssetPaths.Length;
 
         foreach (var item in allAssetPaths)
         {
             if(_checking)
             {
                 iterator++;
                 if (iterator % 100 == 0)
                 {
                     _progress = (float)iterator / listSize;
                     if (EditorUtility.DisplayCancelableProgressBar("Checking assets", _status, _progress))
                     {
                         _checking = false;
                         EditorUtility.ClearProgressBar();
                     }
                 }
                 Object obj = AssetDatabase.LoadAssetAtPath(item, typeof(Object)) as Object;
             
                 if (obj)
                 {
                     allObjects.Add(obj);
                 }
             }
 
             else
             {
                 return;
             }
         }
 
         //Reset progress bar info
         _progress = 0f;
         _status = "Comparing dependencies...";
         listSize = allObjects.Count;
         iterator = 0;
         
         // Find matches and select them
         List<Object> matches = new List<Object>();
         foreach (var assetObject in allObjects)
         {
             if (_checking)
             {
                 iterator++;
                 if (iterator % 100 == 0)
                 {
                     _progress = (float)iterator / listSize;
                     if (EditorUtility.DisplayCancelableProgressBar("Checking assets", _status, _progress))
                     {
                         _checking = false;
                         EditorUtility.ClearProgressBar();
                     }
                 }
                 
                 Object[] dependencies = EditorUtility.CollectDependencies(new Object[] { assetObject });
                 
                 foreach (var dependency in dependencies)
                 {
                     if (selectedObjects.Contains(dependency) && !selectedObjects.Contains(assetObject))
                     {
                         matches.Add(assetObject);
                     }
                 }
             }
             else
             {
                 return;
             }
         }
 
         if (matches.Count == 0)
         {
             EditorUtility.DisplayDialog("No dependants", "No assets depend on the selection", "Ok");
         }
 
         //Clear pogress bar
         _checking = false;
         EditorUtility.ClearProgressBar();
         Selection.objects = matches.ToArray();
     }
 
     [MenuItem("Assets/Select Dependants", true)]
     static bool ValidateFindDependants()
     {
         return Selection.objects.Length > 0;
     }
 }


Any help in what might be going wrong here is greatly appreciated!

editor-error.png (30.0 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ancher · Oct 11, 2016 at 02:25 PM

Just got the same bug.

Seems that problem appears when invoking EditorUtility.CollectDependencies on *.unity or *.guiskin asssets

However, this bug seems to be auto-fixed after invoking AssetDatabase.Refresh() with any change in a database present.

Here is my workaround:

 private static void CrappyUnityBugFix()
 {
     // Make some changes to asset database and trigger refresh which seems to fix the bug somehow

     string dummyXml = Application.dataPath + "/Editor/Dummy.xml";
     string dummyXmlMeta = dummyXml + ".meta";
     if ( File.Exists( dummyXml ) )
     {
         File.Delete( dummyXml );
         if ( File.Exists( dummyXmlMeta ) )
         {
             File.Delete( dummyXmlMeta );
         }
     }
     else
     {
         using ( TextWriter writer = File.CreateText( dummyXml ) )
         {
             writer.WriteLine( "<?xml version=\"1.0\" encoding=\"utf-8\"?><dummy />" );
         }
     }

     AssetDatabase.Refresh();
 }

Comment
Add comment · Share
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

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

234 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

Editorscript: How to reference prefabs in editor not in awake or start 0 Answers

there is no build fail but editor script doesn't work in build 1 Answer

How to see variables of child class with custom editor 0 Answers

Unity Editor - Group Public GameObjects 0 Answers

Editor script: Variable created on gameObject in editor set to missing on runtime 0 Answers


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