|
I have made a script somewhat similar to this one: http://answers.unity3d.com/questions/5020/searching-a-project-for-missing-mono-script But rather than just finding the null entries, I simply want to sweep through and delete them all. By that I mean remove the null references from the GameObjects's list of Components. The documentation for GameObject.AddComponent notes that there is no such thing as RemoveComponent, requiring you to call Object.Destroy() to remove that entry. This is impossible because there is no object to Destroy. Creating a new GameObject and adding the components of the old one to it would invalidate any references to it. Is there a way to do this without laboriously clicking through the UI? NEW EDIT: (in light of comments below) Are these references to some funny objects representing a missing script that the overloaded == operator is treating as equal to null? No, because calling DestroyImmediate() does nothing, and trying to actually de-reference the pointer causes a null reference exception. It must be that there are null pointer entries in the list, and the list is not modifiable by editor script. Here is the demonstration code:
(comments are locked)
|
|
I'm currently facing a similar issue. I can grab and modify the prefab and all it's associated behaviors just fine - including adding and removing MonoBehaviors - but any MonoBehaviors with broken refrences come up as null, and trying to remove or destroy them doesn't work. As far as I can tell, it's impossible to access these MonoBehaviors from the code. I've tried every suggestion so far in this thread, but none of them have worked - Am I stuck going through and removing these by hand? Thanks a bunch in advance. This is not an answer to the question asked. What you've posted is a comment.
May 12 '12 at 04:24 PM
kalvinlyle
(comments are locked)
|
|
Is there a valid solution to this yet ? I have a scene with up to a thousand objects and it will take me hours to remove a bad script that was caused from a click drag when unity chugged..... !!!!!! Not an answer. Please post a comment instead
May 12 '12 at 04:25 PM
kalvinlyle
(comments are locked)
|
|
Mercilessly short answer: You can do this in general in an editor script by Instantiating the object (prefab/asset/whatever you wish to call it) temporarily into the currently open scene, making the desired changes to the object, then using the Editor API to save it back out by replacing the prefab (asset). After that, delete the temporary object from the scene.
(comments are locked)
|
« previous 1 2
