- Home /
Question by
psk · Jun 11, 2013 at 03:53 PM ·
c#requirecomponent
How does RequireComponent expose properties
I have noticed in some scripts we have (c#)
using UnityEngine;
[RequireComponent (typeof (AudioSource))]
public class MyClass : MonoBehaviour
{
void Start()
{
audio.GetSpectrumData(samples, 0, FFTWindow.Rectangular);
}
}
What are the rules defining these auto exposed properties? How are they named?
Comment
Best Answer
Answer by Bunny83 · Jun 11, 2013 at 04:13 PM
There are no rules. Unity just defines some shortcut properties for the most common built-in components. Those properties are not related to RequireComponent at all. They exist in every Component and GameObject instance.
RequireComponent will just auto-add the given component when you add this script to an object, nothing more.
Doh. Of course.. Was over thinking it :) Thanks for the quick answer!
Your answer
![](https://koobas.hobune.stream/wayback/20220613103954im_/https://answers.unity.com/themes/thub/images/avi.jpg)