T GetOrCreate( FindMode flags )

robot_2Generated
code_blocksInput

Description

The GetOrCreate method in the ComponentList class is used to find a component of a specified type within the component list. If the component does not exist, this method will create a new instance of the component and add it to the list. This method is useful for ensuring that a component is always available, either by retrieving an existing one or by creating a new one if necessary.

Usage

To use the GetOrCreate method, specify the type of component you are looking for as the generic type parameter T. You also need to provide a FindMode flag to determine the search behavior. The method will return the component of type T.

Example

// Example usage of GetOrCreate method
var componentList = new ComponentList();
var myComponent = componentList.GetOrCreate<MyComponent>(FindMode.Default);

// This will either find an existing MyComponent or create a new one if it doesn't exist.