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>(GameObject) Method

An extension that allows fetching or adding a component.
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 GameObject gameObject)
    where T : Component;

Type parameters

T
A Unity Component

Parameters

gameObject UnityEngine.GameObject
The GameObject to fetch from or add to

Returns

T
The component specified as T