Click or drag to resize

ExtensionMethodsTryAddComponentT Method

Attempts to add a component to a GameObject. This can fail if there is already a component of some type on the GameObject, and only one is allowed.

Namespace:  DustProductions.Core
Assembly:  DustProductions.Core (in DustProductions.Core.dll) Version: (
public static bool TryAddComponent<T>(
	this GameObject go,
	out T addedComponent
where T : Component


Type: GameObject
The GameObject to add the Component to.
Type: T
The Component added, if one exists.

Type Parameters

The type of the Component to add.

Return Value

Type: Boolean
True if the component is added successfully, false otherwise.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type GameObject. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
See Also