- Home /
How can i remove two scripts from a GameObject that depend on eachother?
Hi.
If i have a GameObject with two scripts called Depend1 and Depend2, and if Depend1 implements the [RequireComponent(typeof(Depend2))], and Depend2 implements the [RequireComponent(typeof(Depend1))], then how am i able to remove the two Components from my GameObject at the same time?
Since the Engine gives me an error about that i cant remove one before the other, then its kinda impossible if i cant remove them both at the same time.
for an interesting question. Is this currently a problem for you at run-time or in the editor?
I'm interested to know why Unity doesn't throw a wobbly about Circular Dependency.
Pick the script which has the least dependence on the other. Take out the require component call. (Lets be honest, it's kinda pointless anyway). In that script, before you disable/destroy etc Replace everything required from the other with Dummy variables.
Its in the editor, however, its not a big problem.
I could obviously just remove the attribute in the script, then remove the component, and then set the attribute back on in the script. But im just curious if theres are better way to do it
Your answer
Follow this Question
Related Questions
Yet another NullReferenceException question. 2 Answers
Why wont this work? (I've done similar 1000 times fine) 1 Answer
Problems deactivating a script. 1 Answer
How to get a value from an array within another script. 1 Answer
BCE0019: 'enabled' is not a member of 'UnityEngine.Component'. ??? 2 Answers