> 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/ks.reactor.client.unity.ksmonoscript-2.md).

# Class ksMonoScript\<Parent, Script>

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

Base class for Reactor MonoBehaviour scripts.

```csharp
public abstract class ksMonoScript<Parent, Script> : MonoBehaviour where Parent : class where Script : ksMonoScript<Parent, Script>
```

#### Type Parameters

`Parent`

Type the script can be attached to.

`Script`

Script type

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) â† Object â† Component â† Behaviour â† MonoBehaviour â† [ksMonoScript\<Parent, Script>](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksmonoscript-2.md)

#### Inherited Members

MonoBehaviour.IsInvoking(), MonoBehaviour.CancelInvoke(), MonoBehaviour.Invoke(string, float), MonoBehaviour.InvokeRepeating(string, float, float), MonoBehaviour.CancelInvoke(string), MonoBehaviour.IsInvoking(string), MonoBehaviour.StartCoroutine(string), MonoBehaviour.StartCoroutine(string, object), MonoBehaviour.StartCoroutine(IEnumerator), MonoBehaviour.StartCoroutine\_Auto(IEnumerator), MonoBehaviour.StopCoroutine(IEnumerator), MonoBehaviour.StopCoroutine(Coroutine), MonoBehaviour.StopCoroutine(string), MonoBehaviour.StopAllCoroutines(), MonoBehaviour.print(object), MonoBehaviour.destroyCancellationToken, MonoBehaviour.useGUILayout, MonoBehaviour.runInEditMode, Behaviour.enabled, Behaviour.isActiveAndEnabled, Component.GetComponent(Type), Component.GetComponent\<T>(), Component.TryGetComponent(Type, out Component), Component.TryGetComponent\<T>(out T), Component.GetComponent(string), Component.GetComponentInChildren(Type, bool), Component.GetComponentInChildren(Type), Component.GetComponentInChildren\<T>(bool), Component.GetComponentInChildren\<T>(), Component.GetComponentsInChildren(Type, bool), Component.GetComponentsInChildren(Type), Component.GetComponentsInChildren\<T>(bool), Component.GetComponentsInChildren\<T>(bool, List\<T>), Component.GetComponentsInChildren\<T>(), Component.GetComponentsInChildren\<T>(List\<T>), Component.GetComponentInParent(Type, bool), Component.GetComponentInParent(Type), Component.GetComponentInParent\<T>(bool), Component.GetComponentInParent\<T>(), Component.GetComponentsInParent(Type, bool), Component.GetComponentsInParent(Type), Component.GetComponentsInParent\<T>(bool), Component.GetComponentsInParent\<T>(bool, List\<T>), Component.GetComponentsInParent\<T>(), Component.GetComponents(Type), Component.GetComponents(Type, List\<Component>), Component.GetComponents\<T>(List\<T>), Component.GetComponents\<T>(), Component.CompareTag(string), Component.SendMessageUpwards(string, object, SendMessageOptions), Component.SendMessageUpwards(string, object), Component.SendMessageUpwards(string), Component.SendMessageUpwards(string, SendMessageOptions), Component.SendMessage(string, object), Component.SendMessage(string), Component.SendMessage(string, object, SendMessageOptions), Component.SendMessage(string, SendMessageOptions), Component.BroadcastMessage(string, object, SendMessageOptions), Component.BroadcastMessage(string, object), Component.BroadcastMessage(string), Component.BroadcastMessage(string, SendMessageOptions), Component.transform, Component.gameObject, Component.tag, 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)

## Properties

### Assets <a href="#ks_reactor_client_unity_ksmonoscript_2_assets" id="ks_reactor_client_unity_ksmonoscript_2_assets"></a>

Loader for [ksScriptAsset](/reactor/api-reference/ks.reactor/ks.reactor.ksscriptasset.md)s in Resources or asset bundles.

```csharp
public ksBaseAssetLoader Assets { get; }
```

#### Property Value

[ksBaseAssetLoader](/reactor/api-reference/ks.reactor/ks.reactor.ksbaseassetloader.md)

### EnableOnAttach <a href="#ks_reactor_client_unity_ksmonoscript_2_enableonattach" id="ks_reactor_client_unity_ksmonoscript_2_enableonattach"></a>

Should this script be enabled when it is attached to the Reactor object (entity/room/player)?

```csharp
public bool EnableOnAttach { get; set; }
```

#### Property Value

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

### InstanceType <a href="#ks_reactor_client_unity_ksmonoscript_2_instancetype" id="ks_reactor_client_unity_ksmonoscript_2_instancetype"></a>

Get the most derived type of this script.

```csharp
public Type InstanceType { get; }
```

#### Property Value

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

### IsAttached <a href="#ks_reactor_client_unity_ksmonoscript_2_isattached" id="ks_reactor_client_unity_ksmonoscript_2_isattached"></a>

Is this script attached to a Reactor object (entity/room/player)? Scripts that are not attached are always disabled. If you enable an unattached script, it will look for a [ksScriptsComponent%602](/reactor/api-reference/ks.reactor.client.unity.md#KS_Reactor_Client_Unity_ksScriptsComponent_602) with an entity/room/player to attach to and disable itself if it does not find one.

```csharp
public bool IsAttached { get; }
```

#### Property Value

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

### IsInitialized <a href="#ks_reactor_client_unity_ksmonoscript_2_isinitialized" id="ks_reactor_client_unity_ksmonoscript_2_isinitialized"></a>

Has [Initialize](/reactor/api-reference/ks.reactor.client.unity.md#KS_Reactor_Client_Unity_ksMonoScript_602_Initialize) been called on this script?

```csharp
public bool IsInitialized { get; }
```

#### Property Value

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

### Room <a href="#ks_reactor_client_unity_ksmonoscript_2_room" id="ks_reactor_client_unity_ksmonoscript_2_room"></a>

Room the script is in.

```csharp
public abstract ksRoom Room { get; }
```

#### Property Value

[ksRoom](/reactor/api-reference/ks.reactor.client.unity/ks.reactor.client.unity.ksroom.md)

### Time <a href="#ks_reactor_client_unity_ksmonoscript_2_time" id="ks_reactor_client_unity_ksmonoscript_2_time"></a>

Server time and local frame delta.

```csharp
public ksClientTime Time { get; }
```

#### Property Value

[ksClientTime](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksclienttime.md)

## Methods

### Attached() <a href="#ks_reactor_client_unity_ksmonoscript_2_attached" id="ks_reactor_client_unity_ksmonoscript_2_attached"></a>

Called immediately when the script/gameobject is attached to its Reactor object (Entity/Room/Player). Other entities may not be spawned yet, and other Reactor scripts may not be attached yet, meaning their Entity/Room/Player reference will be null and they won't be in the [Scripts](/reactor/api-reference/ks.reactor.client.unity.md#KS_Reactor_Client_Unity_ksScriptsComponent_602_Scripts) list yet. Initialization that depends on other scripts or entities should be done from [Initialize](/reactor/api-reference/ks.reactor.client.unity.md#KS_Reactor_Client_Unity_ksMonoScript_602_Initialize). Attached is called on disabled scripts.

```csharp
public virtual void Attached()
```

### Awake() <a href="#ks_reactor_client_unity_ksmonoscript_2_awake" id="ks_reactor_client_unity_ksmonoscript_2_awake"></a>

Called when a script wakes. This method stores the initial enabled state of a script. If the script was not enabled, then we set a value indicating that the script should not be included in the list of scripts on [ksScriptsComponent%602](/reactor/api-reference/ks.reactor.client.unity.md#KS_Reactor_Client_Unity_ksScriptsComponent_602)

```csharp
protected virtual void Awake()
```

### Detached() <a href="#ks_reactor_client_unity_ksmonoscript_2_detached" id="ks_reactor_client_unity_ksmonoscript_2_detached"></a>

Called when the script/gameobject is detached from its Reactor object (Entity/Room/Player). Remove event listeners and perform other clean up logic here.

```csharp
public virtual void Detached()
```

### Initialize() <a href="#ks_reactor_client_unity_ksmonoscript_2_initialize" id="ks_reactor_client_unity_ksmonoscript_2_initialize"></a>

Called after all other scripts are attached and entities are spawned. Initialize is not called on disabled scripts.

```csharp
public virtual void Initialize()
```

### OnDestroy() <a href="#ks_reactor_client_unity_ksmonoscript_2_ondestroy" id="ks_reactor_client_unity_ksmonoscript_2_ondestroy"></a>

Unity OnDestroy. Removes the script from the component and, if the script was is in the component script list, calls [Detached](/reactor/api-reference/ks.reactor.client.unity.md#KS_Reactor_Client_Unity_ksMonoScript_602_Detached). If you override this method, your override should call the base method to ensure the script is cleaned up properly.

```csharp
protected virtual void OnDestroy()
```
