RoR2-ChensHelpers

Contains simple and useful helpers for RoR2 mod creators to use. Mainly caters to Chen's mods.

View on GitHub

ChensHelpers

Chen.Helpers.UnityHelpers.Extensions

Extensions.GetOrAddComponent<T>(Component) Method

An extension that allows fetching or adding a component through the component of the GameObject.
If the GameObject has the component, it will only fetch it and return the component.
If the GameObject does not have the component, it will add one to it and return the component.

public static T GetOrAddComponent<T>(this Component component)
    where T : Component;

Type parameters

T
A Unity Component

Parameters

component UnityEngine.Component
The GameObject of the component to fetch from or add to

Returns

T
The component specified as T