# DefaultValueAttribute

Kind: Class · Namespace: Sansar.Script · Assembly: Sansar.Script.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar.Script">Namespace <a href="/scripting/api/sansar.script"><code>Sansar.Script</code></a></span>
<span>Inherits <a href="https://learn.microsoft.com/dotnet/api/system.attribute">Attribute</a></span>
</div>

<span id="T:Sansar.Script.DefaultValueAttribute"></span>

Set a default value to show in the script properties field.

```csharp
[System.AttributeUsage(System.AttributeTargets.Field)]
public class DefaultValueAttribute : Attribute
```

## Remarks

Unless specified by this attribute all fields shown in script properties are initialized to the default value for their type (usually 0 or empty string equivalents.). Note that Vector and Quaternions require an appropriately formatted string to work correctly.  Vectors start with &#39;&lt;&#39;, have 3 or 4 numerical elements seperated by commas, and end with &#39;&gt;&#39;. Quaternions start with &#39;\[&#39;, have 4 numerical elements seperated by commas, and end with &#39;\]&#39;

## Example

```csharp
[DefaultValue("Default Event")]
public string MyString = null;

[DefaultValue(12.34)]
public float MyFloat = 1;

[DefaultValue("<1.2,3.4,5.6>")]
public Sansar.Vector MyVector;

[DefaultValue("[1.2,3.4,5.6,7.8]")]
public Sansar.Quaternion MyQuaternion;

[DefaultValue("(1.2,3.4,5.6,7.8)")]
public Sansar.Color MyColor;

[DefaultValue(true)]
public bool MyBool;

[DefaultValue(2)]
[Range(-20, 5)]
public int myInt;
```

## Members at a glance

| Kind | Members |
|---|---|
| **Constructors** | [DefaultValueAttribute](#defaultvalueattribute) |

## Constructors

### DefaultValueAttribute

<div class="api-card" id="ctor-boolean">
<span id="M:Sansar.Script.DefaultValueAttribute.#ctor(System.Boolean)"></span>
<span id="C:Sansar.Script.DefaultValueAttribute(System.Boolean)"></span>

```csharp signature
public DefaultValueAttribute(bool value)
```

Set a default bool value to show in the script properties for this field. Without the DefaultValue attribute bools default to &#39;false&#39;.

| Parameter | Type | Description |
|---|---|---|
| `value` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The default boolvalue to show in script properties. |

<details class="api-example" open><summary>Example</summary>

```csharp
[DefaultValue(true)]
public bool MyBool;
```

</details>

</div>

<div class="api-card" id="ctor-byte">
<span id="M:Sansar.Script.DefaultValueAttribute.#ctor(System.Byte)"></span>
<span id="C:Sansar.Script.DefaultValueAttribute(System.Byte)"></span>

```csharp signature
public DefaultValueAttribute(byte value)
```

Set a default byte value to show in the script properties for this field.  Without the DefaultValue attribute bytes default to 0.

| Parameter | Type | Description |
|---|---|---|
| `value` | [byte](https://learn.microsoft.com/dotnet/api/system.byte) | The default byte value to show in script properties. |

<details class="api-example" open><summary>Example</summary>

```csharp
[DefaultValue(0x00C9)]
public byte MyField;
```

</details>

</div>

<div class="api-card" id="ctor-double">
<span id="M:Sansar.Script.DefaultValueAttribute.#ctor(System.Double)"></span>
<span id="C:Sansar.Script.DefaultValueAttribute(System.Double)"></span>

```csharp signature
public DefaultValueAttribute(double value)
```

Set a default double value to show in the script properties for this field.  Without the DefaultValue attribute doubles default to 0.0.

| Parameter | Type | Description |
|---|---|---|
| `value` | [double](https://learn.microsoft.com/dotnet/api/system.double) | The default double value to show in script properties. |

<details class="api-remarks"><summary>Remarks</summary>

Script properties only support floats, this constructor is provided for convenience and values will be converted to floats.

</details>

<details class="api-example" open><summary>Example</summary>

```csharp
[DefaultValue(12.34)]
public double MyField;
```

</details>

</div>

<div class="api-card" id="ctor-double-2">
<span id="M:Sansar.Script.DefaultValueAttribute.#ctor(System.Double[])"></span>
<span id="C:Sansar.Script.DefaultValueAttribute(System.Double[])"></span>

```csharp signature
public DefaultValueAttribute(params double[] value)
```

Set a default double value to show in the script properties for this field.  Without the DefaultValue attribute doubles default to 0.0.

| Parameter | Type | Description |
|---|---|---|
| `value` | [double](https://learn.microsoft.com/dotnet/api/system.double)\[\] | The default double value to show in script properties. |

<details class="api-remarks"><summary>Remarks</summary>

Script properties only support floats, this constructor is provided for convenience and values will be converted to floats.

</details>

<details class="api-example" open><summary>Example</summary>

```csharp
[DefaultValue(1.3, 2.4, 3.5)]
public Vector MyField;
```

</details>

</div>

<div class="api-card" id="ctor-int16">
<span id="M:Sansar.Script.DefaultValueAttribute.#ctor(System.Int16)"></span>
<span id="C:Sansar.Script.DefaultValueAttribute(System.Int16)"></span>

```csharp signature
public DefaultValueAttribute(short value)
```

Set a default short value to show in the script properties for this field.  Without the DefaultValue attribute shorts default to 0.

| Parameter | Type | Description |
|---|---|---|
| `value` | [short](https://learn.microsoft.com/dotnet/api/system.int16) | The default short value to show in script properties. |

<details class="api-example" open><summary>Example</summary>

```csharp
[DefaultValue(123)]
public short MyField;
```

</details>

</div>

<div class="api-card" id="ctor-int32">
<span id="M:Sansar.Script.DefaultValueAttribute.#ctor(System.Int32)"></span>
<span id="C:Sansar.Script.DefaultValueAttribute(System.Int32)"></span>

```csharp signature
public DefaultValueAttribute(int value)
```

Set a default int value to show in the script properties for this field.  Without the DefaultValue attribute ints default to 0.

| Parameter | Type | Description |
|---|---|---|
| `value` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | The default int value to show in script properties. |

<details class="api-example" open><summary>Example</summary>

```csharp
[DefaultValue(123)]
public int MyField;
```

</details>

</div>

<div class="api-card" id="ctor-int64">
<span id="M:Sansar.Script.DefaultValueAttribute.#ctor(System.Int64)"></span>
<span id="C:Sansar.Script.DefaultValueAttribute(System.Int64)"></span>

```csharp signature
public DefaultValueAttribute(long value)
```

Set a default long value to show in the script properties for this field.  Without the DefaultValue attribute longs default to 0.

| Parameter | Type | Description |
|---|---|---|
| `value` | [long](https://learn.microsoft.com/dotnet/api/system.int64) | The default long value to show in script properties. |

<details class="api-example" open><summary>Example</summary>

```csharp
[DefaultValue(123)]
public long MyField;
```

</details>

</div>

<div class="api-card" id="ctor-single">
<span id="M:Sansar.Script.DefaultValueAttribute.#ctor(System.Single)"></span>
<span id="C:Sansar.Script.DefaultValueAttribute(System.Single)"></span>

```csharp signature
public DefaultValueAttribute(float value)
```

Set a default float value to show in the script properties for this field.  Without the DefaultValue attribute floats default to 0.0.

| Parameter | Type | Description |
|---|---|---|
| `value` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The default float value to show in script properties. |

<details class="api-remarks"><summary>Remarks</summary>

Script properties only support up to 32bit int, this constructor is provided for convenience and values will be converted to 32bit int.

</details>

<details class="api-example" open><summary>Example</summary>

```csharp
[DefaultValue(12.34)]
public float MyField;
```

</details>

</div>

<div class="api-card" id="ctor-string">
<span id="M:Sansar.Script.DefaultValueAttribute.#ctor(System.String)"></span>
<span id="C:Sansar.Script.DefaultValueAttribute(System.String)"></span>

```csharp signature
public DefaultValueAttribute(string value)
```

Set a default string value to show in the script properties for this field. Without the DefaultValue attribute strings default to an empty string.

| Parameter | Type | Description |
|---|---|---|
| `value` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The default value in string form for strings, quaternions and vector fields. |

<details class="api-remarks"><summary>Remarks</summary>

The string DefaultValue attribute can be used to set Vector and Quaternions with an appropriately formatted string.  Vectors start with &#39;&lt;&#39;, have 3 or 4 numerical elements seperated by commas, and end with &#39;&gt;&#39;. Quaternions start with &#39;\[&#39;, have 4 numerical elements seperated by commas, and end with &#39;\]&#39;

</details>

<details class="api-example" open><summary>Example</summary>

```csharp
[DefaultValue("Default Event")]
public string MyString = null;

[DefaultValue("<1.2,3.4,5.6>")]
public Sansar.Vector MyVector;

[DefaultValue("[1.2,3.4,5.6,7.8]")]
public Sansar.Quaternion MyQuaternion;

[DefaultValue("(1.2,3.4,5.6,7.8)")]
public Sansar.Quaternion MyQuaternion;
```

</details>

</div>




<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>