- Home /
Is RequireComponent[typeof(CustomScript)] possible?
Hi, Is it possible to automatically load a custom script component with this attribute?
Answer by Berenger · Jun 05, 2012 at 10:58 PM
Absolutely. The script must inherit from MonoBehaviour and must compile though.
Answer by DSivtsov · Nov 21, 2021 at 06:50 PM
@Berenger In Unity 2020.3 it's normally works:
[RequireComponent(typeof(CtrlVerticalSpeedMoveCharater))]
public class MainCtrlStateMachine : MonoBehaviour
{....}
Note. public class CtrlVerticalSpeedMoveCharater : MonoBehaviour and therefore it can be attached to GameObject.
If you talk about the "CustomSciprt" which isn't derived from MonoBehaviour (ScirptableObject or standard C# sciprt) in this case it doesn't have any sense, but "it "can be did by common c# technics.
Your answer
![](https://koobas.hobune.stream/wayback/20220613072413im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Custom attributes? 3 Answers
How to write a custom attribute? 1 Answer
Is it possible to add an icon to indicate there is an editor tooltip decorating a variable? 0 Answers
Custom [Require*] attribute 2 Answers
bumpcolorspec not working in unity3? 2 Answers