Click or drag to resize

ExtensionMethodsTryGetComponentT Method (GameObject, T, Boolean)

Attempts to get a component on a gameobject.

Namespace:  DustProductions.Core
Assembly:  DustProductions.Core (in DustProductions.Core.dll) Version: (
public static bool TryGetComponent<T>(
	this GameObject go,
	ref T refComponent,
	bool tryAddingComponent = false
where T : Component


Type: GameObject
The gameobject you are searching
Type: T
A reference to the component found, if it exists
tryAddingComponent (Optional)
Type: SystemBoolean
Optional parameter to attempt adding the component if it cannot be found, defaulted to false

Type Parameters

The type of component you are looking for

Return Value

Type: Boolean
True if a component is found (either in the component passed in, or on the object being searched) or successfully added

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