# Simple Script

### SimpleScript Class

Extend SimpleScript to create a script that can be used on content that is natively in the scene. This is the primary script type in Sansar.

### Syntax

\[Sansar.Script.Interface]\
\[System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", true)]\
public abstract class **SimpleScript** : [Sansar.Script.ScriptBase](https://help.sansar.com/hc/en-us/articles/115003549048)

### Member Details

#### SimpleScript Constructor

> This constructor is called before any properties have been set. Override Sansar.Script.SimpleScript.SimpleInit() to initialize the script after properties have been set and events setup.
>
> #### Syntax
>
> \[Sansar.Script.Interface]\
> \[System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)]\
> protected **SimpleScript** ()
>
> #### Remarks
>
> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### GetSubscription Method

> Get the IEventSubscription for any of the registered event subscription methods
>
> #### Syntax
>
> **Parameters**
>
> > *methodName*
> >
> > The n
>
> **Returns**
>
> > An IEventSubscription interface that can be used to unsubscribe from a registered event.
>
> #### Remarks
>
> #### Example

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><strong>C# Example</strong></td></tr><tr><td><pre><code>            GetSubscription("OnChat").Unsubscribe();
</code></pre></td></tr></tbody></table>

|

> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### Init Method

> Init() initializes all event subscriptions for the overridable methods in SimpleScript
>
> #### Syntax
>
> \[Sansar.Script.Api]\
> public override sealed [void](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Void) **Init** ()
>
> **See Also**
>
> #### Remarks
>
> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### ObjectPrivate Property

> The ObjectPrivate this script is attached to if it is attached to an object.
>
> #### Syntax
>
> \[Sansar.Script.NonReflective]\
> \[get: Sansar.Script.Interface]\
> public [ObjectPrivate](https://help.sansar.com/hc/en-us/articles/115003361366) **ObjectPrivate** { protected get; set; }
>
> **Value**
>
> > The scene object this script is attached to if it is attached to an object, null otherwise.
>
> #### Remarks
>
> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### OnAddUser Method

> Code in OnAddUser will run whenever a user enters the scene.
>
> #### Syntax
>
> \[Sansar.Script.Interface]\
> \[System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)]\
> protected virtual [void](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Void) **OnAddUser** ([AgentPrivate](https://help.sansar.com/hc/en-us/articles/115003361386) agent)
>
> **See Also**
>
> **Parameters**
>
> > *agent*
> >
> > The AgentPrivate for the user that has joined the scene.
>
> #### Remarks
>
> #### Example

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><strong>C# Example</strong></td></tr><tr><td><pre><code>            protected override OnAddUser(AgentPrivate agent)
</code></pre></td></tr></tbody></table>

```
        {
           agent.SendChat($"Welcome to the {ScenePrivate.SceneInfo.ExperienceName} scene!");
        }
        
```

|

> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### OnChat Method

> Code in OnChat will run whenever chat is heard.
>
> #### Syntax
>
> \[Sansar.Script.Interface]\
> \[System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)]\
> protected virtual [void](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Void) **OnChat** ([ChatData](https://help.sansar.com/hc/en-us/articles/115003435067) data)
>
> **See Also**
>
> **Parameters**
>
> > *data*
> >
> > ChatData for the message.
>
> #### Remarks
>
> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### OnCollision Method

> Receive events whenever the object this script is on collides with something or someone.
>
> #### Syntax
>
> \[Sansar.Script.Interface]\
> \[System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)]\
> protected virtual [void](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Void) **OnCollision** ([CollisionData](https://help.sansar.com/hc/en-us/articles/115003438203) data)
>
> **See Also**
>
> **Parameters**
>
> > *data*
> >
> > The CollisionData about the collision.
>
> #### Remarks
>
> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### OnRemoveUser Method

> Code in OnRemoveUser will run whenever a user leaves the scene.
>
> #### Syntax
>
> \[Sansar.Script.Interface]\
> \[System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)]\
> protected virtual [void](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Void) **OnRemoveUser** ([AgentInfo](https://help.sansar.com/hc/en-us/articles/115003435467) data)
>
> **See Also**
>
> **Parameters**
>
> > *data*
> >
> > UserData for the user that has left the scene.
>
> #### Remarks
>
> #### Example

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><strong>C# Example</strong></td></tr><tr><td><pre><code>// This event occurs when a user leaves the scene
</code></pre></td></tr></tbody></table>

```
        protected override void OnRemoveUser(AgentInfo info)
        {
            Log.Write($"{info.Name} has left the region.");
        }
```

|

> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### OnScriptEvent Method

> Receive events from other scripts.
>
> #### Syntax
>
> \[Sansar.Script.Interface]\
> \[System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)]\
> protected virtual [void](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Void) **OnScriptEvent** ([Sansar.Script.ScriptId](/latest/script-api-docs/sansar-script-namespace/scriptid.md) sourceScriptId, [object](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Object) data)
>
> **See Also**
>
> **Parameters**
>
> > *sourceScriptId*
> >
> > The [Sansar.Script.ScriptId](/latest/script-api-docs/sansar-script-namespace/scriptid.md) of the script that sent the message
> >
> > *data*
> >
> > The data sent by another script, as an object.
>
> #### Remarks
>
> #### Example

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><strong>C# Example</strong></td></tr><tr><td><pre><code>            // Send events to this handler from other simple scripts with: PostScriptEvent("AddPosition", myVector);
</code></pre></td></tr></tbody></table>

```
        [OnScriptEventOptions(EventName="AddPosition")]
        protected override void OnScriptEvent(object eventData)
        {
            Vector newPos = eventData as Vector;
            if (newPos != null) AllPositions.Add(newPos);
        }
        
```

|

> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### OnTimer Method

> Code in OnTimer will run at regular intervals.
>
> #### Syntax
>
> \[Sansar.Script.Interface]\
> \[System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)]\
> protected virtual [void](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Void) **OnTimer** ()
>
> #### Remarks
>
> #### Example

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><strong>C# Example</strong></td></tr><tr><td><pre><code>            // Set OnTimer to happen once every minute.
</code></pre></td></tr></tbody></table>

```
        [OnTimerOptions(Rate=60)]
        protected override void OnTimer()
        
```

|

> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### RigidBodyComponent Property

> The first RigidBodyComponent on ObjectPrivate
>
> #### Syntax
>
> \[get: Sansar.Script.Interface]\
> protected [RigidBodyComponent](https://help.sansar.com/hc/en-us/articles/115003513667) **RigidBodyComponent** { get; }
>
> **Value**
>
> > The first [SimpleScript.RigidBodyComponent](https://help.sansar.com/hc/en-us/articles/360000126063#P:Sansar.Simulation.SimpleScript.RigidBodyComponent) on the object this script is attached to.
>
> #### Remarks
>
> This is a convenience for:

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><strong>C# Example</strong></td></tr><tr><td><pre><code>            RigidBodyComponent rigidbody;
</code></pre></td></tr></tbody></table>

```
         if (ObjectPrivate != null &#x26;&#x26; ObjectPrivate.TryGetFirstComponent(out rigidbody))
        {
            // Do something with rigidbody
        }
        
```

|

> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### ScenePrivate Property

> The Scene API for the Scene this script is a part of if the script is attached to scene content.
>
> #### Syntax
>
> \[Sansar.Script.NonReflective]\
> \[get: Sansar.Script.Interface]\
> public [ScenePrivate](https://help.sansar.com/hc/en-us/articles/115003342683) **ScenePrivate** { protected get; set; }
>
> **Value**
>
> > The Scene API for this scene if this script was attached to scene content, null otherwise.
>
> #### Remarks
>
> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

#### SimpleInit Method

> Override SimpleInit for script setup, such as subscribing to other events or
>
> #### Syntax
>
> \[Sansar.Script.Interface]\
> \[System.Obsolete("SimpleScript is deprecated and will not receive new features. Please use SceneObjectScript or ObjectScript.", false)]\
> protected virtual [void](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Void) **SimpleInit** ()
>
> #### Remarks
>
> #### Requirements
>
> **Namespace:** Sansar.Simulation\
> **Assembly:** Sansar.Simulation (in Sansar.Simulation.dll)\
> **Assembly Versions:** 1.1.0.0
>
> ***

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sansar.com/latest/script-api-docs/sansar-simulation-namespace/simple-script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
