> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/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/reactor/api-reference/ks.reactor.client.unity.editor/ks.reactor.client.unity.editor.ksscriptgenerator.md).

# Class ksScriptGenerator

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

Provides methods for generating scripts that can be used by script templates.

```csharp
public class ksScriptGenerator : ksSingleton<ksScriptGenerator>
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← Object ← ScriptableObject ← [ksSingleton\<ksScriptGenerator>](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kssingleton-1.md) ← [ksScriptGenerator](/reactor/api-reference/ks.reactor.client.unity.editor/ks.reactor.client.unity.editor.ksscriptgenerator.md)

#### Inherited Members

[ksSingleton\<ksScriptGenerator>.Get()](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kssingleton-1.md#KS_Unity_Editor_ksSingleton_1_Get), [ksSingleton\<ksScriptGenerator>.Initialize()](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kssingleton-1.md#KS_Unity_Editor_ksSingleton_1_Initialize), [ksSingleton\<ksScriptGenerator>.Create()](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kssingleton-1.md#KS_Unity_Editor_ksSingleton_1_Create), ScriptableObject.SetDirty(), ScriptableObject.CreateInstance(string), ScriptableObject.CreateInstance(Type), ScriptableObject.CreateInstance\<T>(), Object.GetInstanceID(), Object.GetHashCode(), Object.Equals(object), Object.Instantiate(Object, Vector3, Quaternion), Object.Instantiate(Object, Vector3, Quaternion, Transform), Object.Instantiate(Object), Object.Instantiate(Object, Transform), Object.Instantiate(Object, Transform, bool), Object.Instantiate\<T>(T), Object.Instantiate\<T>(T, Vector3, Quaternion), Object.Instantiate\<T>(T, Vector3, Quaternion, Transform), Object.Instantiate\<T>(T, Transform), Object.Instantiate\<T>(T, Transform, bool), Object.Destroy(Object, float), Object.Destroy(Object), Object.DestroyImmediate(Object, bool), Object.DestroyImmediate(Object), Object.FindObjectsOfType(Type), Object.FindObjectsOfType(Type, bool), Object.FindObjectsByType(Type, FindObjectsSortMode), Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode), Object.DontDestroyOnLoad(Object), Object.DestroyObject(Object, float), Object.DestroyObject(Object), Object.FindSceneObjectsOfType(Type), Object.FindObjectsOfTypeIncludingAssets(Type), Object.FindObjectsOfType\<T>(), Object.FindObjectsByType\<T>(FindObjectsSortMode), Object.FindObjectsOfType\<T>(bool), Object.FindObjectsByType\<T>(FindObjectsInactive, FindObjectsSortMode), Object.FindObjectOfType\<T>(), Object.FindObjectOfType\<T>(bool), Object.FindFirstObjectByType\<T>(), Object.FindAnyObjectByType\<T>(), Object.FindFirstObjectByType\<T>(FindObjectsInactive), Object.FindAnyObjectByType\<T>(FindObjectsInactive), Object.FindObjectsOfTypeAll(Type), Object.FindObjectOfType(Type), Object.FindFirstObjectByType(Type), Object.FindAnyObjectByType(Type), Object.FindObjectOfType(Type, bool), Object.FindFirstObjectByType(Type, FindObjectsInactive), Object.FindAnyObjectByType(Type, FindObjectsInactive), Object.ToString(), Object.name, Object.hideFlags, [object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object\)), [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object-system-object\)), [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype), [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone), [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Methods

### DeleteMatchingLines(string, string) <a href="#ks_reactor_client_unity_editor_ksscriptgenerator_deletematchinglines_system_string_system_string" id="ks_reactor_client_unity_editor_ksscriptgenerator_deletematchinglines_system_string_system_string"></a>

Deletes all lines that have an occurence of `substr` from `template`.

```csharp
public string DeleteMatchingLines(string template, string substr)
```

#### Parameters

`template` [string](https://learn.microsoft.com/dotnet/api/system.string)

Template to delete lines from.

`substr` [string](https://learn.microsoft.com/dotnet/api/system.string)

Delete lines that contain this string.

#### Returns

[string](https://learn.microsoft.com/dotnet/api/system.string)

The `template` with lines that contain `substr` deleted.

### LoadAttachments() <a href="#ks_reactor_client_unity_editor_ksscriptgenerator_loadattachments" id="ks_reactor_client_unity_editor_ksscriptgenerator_loadattachments"></a>

Called when Unity starts. Sometimes we need to attach newly created scripts to game objects, but we cannot attach the script until Unity compiles it, and when Unity compiles scripts we lose any non-serialized state. This function attaches scripts to game objects based on serialized data written before scripts were recompiled.

```csharp
public void LoadAttachments()
```

### SaveAttachments(string, GameObject\[]) <a href="#ks_reactor_client_unity_editor_ksscriptgenerator_saveattachments_system_string_unityengine_gameobjec" id="ks_reactor_client_unity_editor_ksscriptgenerator_saveattachments_system_string_unityengine_gameobjec"></a>

Saves script attachment data so a script can be attached to game objects once Unity finishes compiling scripts.

```csharp
public void SaveAttachments(string path, GameObject[] gameObjects)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

Path to script to attach.

`gameObjects` GameObject\[]

Game objects to attach script to.

### Write(string, string) <a href="#ks_reactor_client_unity_editor_ksscriptgenerator_write_system_string_system_string" id="ks_reactor_client_unity_editor_ksscriptgenerator_write_system_string_system_string"></a>

Writes a file.

```csharp
public bool Write(string path, string data)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

Path to write to.

`data` [string](https://learn.microsoft.com/dotnet/api/system.string)

Data to write.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

True if the file was written successfully.
