> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/scene-fusion/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/scene-fusion/api-reference/ks.scenefusion.client.unity.editor/ks.scenefusion.client.unity.editor.sfcomponentutils.md).

# Class sfComponentUtils

Namespace: [KS.SceneFusion.Client.Unity.Editor](/scene-fusion/api-reference/ks.scenefusion.client.unity.editor.md)\
Assembly: KSUnity-Source.dll

Component utility functions.

```csharp
public class sfComponentUtils
```

#### Inheritance

object ← [sfComponentUtils](/scene-fusion/api-reference/ks.scenefusion.client.unity.editor/ks.scenefusion.client.unity.editor.sfcomponentutils.md)

## Methods

### AddComponent(GameObject, string) <a href="#ks_scenefusion_client_unity_editor_sfcomponentutils_addcomponent_unityengine_gameobject_system_strin" id="ks_scenefusion_client_unity_editor_sfcomponentutils_addcomponent_unityengine_gameobject_system_strin"></a>

Adds a component to a game object by its type name. You can get the name using GetName.

```csharp
public static Component AddComponent(GameObject gameObject, string name)
```

#### Parameters

`gameObject` GameObject

gameObject to add component to.

`name` string

name of component to add.

#### Returns

Component

### GetClassAndAssemblyName(string, out string, out string) <a href="#ks_scenefusion_client_unity_editor_sfcomponentutils_getclassandassemblyname_system_string_system_str" id="ks_scenefusion_client_unity_editor_sfcomponentutils_getclassandassemblyname_system_string_system_str"></a>

Gets the class name and assembly name from a component name, and returns true if the component is a Monobehaviour. The assembly name will is null for non-Monobehaviours, and empty string for Monobehaviours in the default assembly Assembly-CSharp. Use GetName to get the component name.

```csharp
public static bool GetClassAndAssemblyName(string name, out string className, out string assemblyName)
```

#### Parameters

`name` string

`className` string

className including namespace.

`assemblyName` string

#### Returns

bool

true if the component is a Monobehaviour.

### GetDisplayName(string) <a href="#ks_scenefusion_client_unity_editor_sfcomponentutils_getdisplayname_system_string" id="ks_scenefusion_client_unity_editor_sfcomponentutils_getdisplayname_system_string"></a>

Converts a component name from GetName to a display name. If the name begins with a '#' it is removed, and all other '#'s are changed to '.'s.

```csharp
public static string GetDisplayName(string name)
```

#### Parameters

`name` string

#### Returns

string

display name.

### GetName(Component) <a href="#ks_scenefusion_client_unity_editor_sfcomponentutils_getname_unityengine_component" id="ks_scenefusion_client_unity_editor_sfcomponentutils_getname_unityengine_component"></a>

Gets the name of a component. For Unity components the namespace is only included if it is not part of UnityEngine. For Monobehaviours this is the assembly name + class name with name space seperated by a '#'. If the assembly is Assembly-CSharp (the default for scripts) the assembly name is not included and the name begins with a '#'.

```csharp
public static string GetName(Component component)
```

#### Parameters

`component` Component

component to get name for.

#### Returns

string

name

### SetParent(GameObject, GameObject) <a href="#ks_scenefusion_client_unity_editor_sfcomponentutils_setparent_unityengine_gameobject_unityengine_gam" id="ks_scenefusion_client_unity_editor_sfcomponentutils_setparent_unityengine_gameobject_unityengine_gam"></a>

Sets a transform's parent without modifying the transform's local position, rotation, or scale values. Applies pending serialized property changes to the transform, its old parent, and new parent to prevent corrupting the hierarchy.

```csharp
public static void SetParent(GameObject child, GameObject parent)
```

#### Parameters

`child` GameObject

child to set parent for.

`parent` GameObject

parent to set. Null to make the child a root object.

### SetParent(Transform, Transform) <a href="#ks_scenefusion_client_unity_editor_sfcomponentutils_setparent_unityengine_transform_unityengine_tran" id="ks_scenefusion_client_unity_editor_sfcomponentutils_setparent_unityengine_transform_unityengine_tran"></a>

Sets a transform's parent without modifying the transform's local position, rotation, or scale values. Applies pending serialized property changes to the transform, its old parent, and new parent to prevent corrupting the hierarchy. Unlike Unity's parent changing methods, this also works on prefab asset transforms as long as the child and parent reside within the same prefab.

```csharp
public static void SetParent(Transform child, Transform parent)
```

#### Parameters

`child` Transform

child to set parent for.

`parent` Transform

parent to set. Null to make the child a root object.
