- Home /
Question by
IsaiahKelly · Aug 31, 2016 at 11:17 PM ·
destroycomponentsremovedependenciesrequired
Check If Component is Requred by Another
Is it possible to check in code if a component is required by any others?
You can easily destroy any component with the Destroy() function. However, destroying components that are required by any others leads to crashes. So I need to find some way of checking to make sure no other components are dependent on the one I'm about to destory.
Unity already checks for this if you try to remove a component through it's context menu: So is there any way to do a check like this yourself in code?
cant-remove.png
(4.9 kB)
Comment
Answer by LTK · Sep 01, 2016 at 03:42 AM
Unity use attribute to check, you can see here: https://docs.unity3d.com/ScriptReference/RequireComponent.html