When added before a component class will make sure that whenever the component with the attribute is added to GameObjects, all components matching the specified types are also present on the same GameObject.
Attribute Target
Component class
Example
using System; using UnityEngine; using Sisus.Attributes; [RequireComponents(typeof(Camera), typeof(AudioListener)), DisallowMultipleComponent] public class MainCamera : MonoBehaviour { public static MainCamera Instance { get; private set; } void Awake() { if(Instance != null && Instance != this) { Debug.LogWarning("MainCamera created with another MainCamera already existing in the scene. Demoting previous MainMamera into a normal camera.", this); if(Instance.CompareTag("MainCamera")) { Instance.tag = "Untagged"; } if(string.Equals(Instance.name, "Main Camera", StringComparison.Ordinal)) { Instance.name = "Camera"; } Destroy(Instance.GetComponent<AudioSource>()); Destroy(Instance); } Instance = this; tag = "MainCamera"; if(string.Equals(name, "Camera", StringComparison.Ordinal)) { Instance.name = "Main Camera"; } } }
Example Result (Add Component)
Example Result (Remove Component)