Back to Writing
NOTESunitygame-devcsharpcomponentsattributes

Unity - RequireComponent Attribute

March 15, 2020Updated Feb 17, 2026

An attribute I stumbled upon recently,

as the name suggests — "require component" —

when you attach this script to a GameObject,

![](

1E-Qz9a2rvhUgc-oHwg.LeNGjsEzoWzYdwgJdFqmTyA0GFJbBTRohGfu9owQ-vsg.PNG.cdw0424/image.png?type=w966)

it automatically adds the class specified as a parameter in the typeof function as a component on the same GameObject.