ScriptableNestedObject

ScriptableNestedObject

ScriptableNestedObject is an extension of NestedObject that allows the storage of user-defined attributes inside the object. It is useful for storing internal data used by the script persistently.

Any data stored into ScriptableNestedObject will be copied and pasted along with the object itself, and will be retained after saving and re-loading the project.

(supported since 2.1.2)

Extends

Methods

clearScriptData()

Remove all script data from the object's storage. Note: use with caution as this could also remove data created by other scripts.

getIndexInParent() → {number}

Inherited From:

Get index of the current object in its parent. In Lua, this index starts from 1. In JavaScript, this index starts from 0.

Returns:
Type
number

getParent() → {NestedObject|undefined}

Inherited From:

Get the parent NestedObject. Return undefined if the current object is not attached to a parent.

Returns:
Type
NestedObject | undefined

getScriptData(key) → {any}

Retrieve a value from the object's script data storage by key. Returns undefined if the key does not exist.

Parameters:
Name Type Description
key string

The key to retrieve the value for

Returns:

The stored value, or undefined if key doesn't exist

Type
any

getScriptDataKeys() → {Array.<string>}

Get all keys currently stored in the object's script data storage.

Returns:

Array of all stored keys

Type
Array.<string>

hasScriptData(key) → {boolean}

Check whether a key exists in the object's script data storage.

Parameters:
Name Type Description
key string

The key to check for

Returns:

true if the key exists, false otherwise

Type
boolean

isMemoryManaged() → {boolean}

Inherited From:

Check whether or not the current object is memory managed (i.e. garbage collected by the script environment).

Returns:
Type
boolean

removeScriptData(key)

Remove a key-value pair from the object's script data storage.

Parameters:
Name Type Description
key string

The key to remove

setScriptData(key, value)

Store a value with the specified key in the object's script data storage. The value must be JSON-serializable.

Parameters:
Name Type Description
key string

The key to store the value under

value any

The value to store (must be JSON-serializable)