# Referencing Scene Components

## Referencing scene components with scripts

[Scripts](https://help.sansar.com/hc/en-us/articles/115003373967-Sansar-Script-API) can contain direct references to *Light*, *Audio*, *RigidBody* or *Animation* components in the same scene. Among other capabilities, these component references allow you to accomplish tasks such as saving a [collection](https://help.sansar.com/hc/en-us/articles/360024668731-Working-with-collections-grouped-objects-) of connected objects for sale in the [Sansar Store](https://docs.sansar.com/latest/sansarstore/selling-your-content/selling-items-in-store).

In this article, we'll use the terms *source* and *target*. The *source* is a [script parameter](https://help.sansar.com/hc/en-us/articles/115003128103-Setting-script-parameters) that contains the *target* as its value.

### Creating a reference

You can create a reference by copying a target component from the Object Structure panel (or from another component reference) and pasting it into a script's corresponding parameter field in the Properties panel.

The component script's parameter text cannot be edited directly. Right-click the parameter field and select **Paste** to set it to the last-copied component, if the copied component's type matches the parameter's type (Light, Audio, RigidBody, or Animation). Right-click the field and select **Clear** to set the value to an empty object. You may also paste a target into an element of a parameter array if the script is designed to accept an array of targets.

![](https://1251409636-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeFXiTZShM8YWMV94n1eV%2Fuploads%2Fgit-blob-de8c04a47cf800cdfde3ec09442497a9460858cc%2FCopy%20component%20source.png?alt=media) ![](https://1251409636-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeFXiTZShM8YWMV94n1eV%2Fuploads%2Fgit-blob-3b0e48ba7591fea0d4688face129a131c1a55282%2FPaste%20component%20target.png?alt=media)

### Duplication

When a set of interacting items is duplicated, all the interactions get duplicated accordingly:

* If a component reference source and target are both included in a duplicated set, then the duplicate of the source points to the duplicate of the target.
* If the target is outside the duplicated set, then the source points to the original target.

### Collections (grouped objects)

If you save a [collection](https://help.sansar.com/hc/en-us/articles/360024668731-Working-with-collections-grouped-objects-) to your inventory contains both the source and target for a reference, then that reference is retained in the inventory collection.

All intact references will be restored when the item is dragged into a scene. This allow you to sell a collection of interacting objects on the Sansar Store, or make several independent instances of the collection.

### Broken references

An script parameter can link to another scene element that has been deleted. When this happens, the parameter is displayed as **(not found)** in the Properties panel.

When you build your scene, you will receive a warning about any broken references that were detected during the build process. There is currently no warning when a targeted item is deleted. However the Undo function may recover the reference if it is still available.

When creating a [collection](https://help.sansar.com/hc/en-us/articles/360024668731-Working-with-collections-grouped-objects-), if the selected items contain broken links or if target components are not part of the selection, you will be warned and given a chance to cancel the creation of the collection. If you choose to disregard the warning, the broken links will be erased from the items in the collection.

![](https://1251409636-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeFXiTZShM8YWMV94n1eV%2Fuploads%2Fgit-blob-57159ac4c2156ae57e61b7cd1f29dde999b44ac3%2Fimage2.png?alt=media) ![](https://1251409636-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeFXiTZShM8YWMV94n1eV%2Fuploads%2Fgit-blob-d227885978af72eda5d0b1dfdcab16a5d056efc3%2Fimage4.png?alt=media) ![](https://1251409636-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeFXiTZShM8YWMV94n1eV%2Fuploads%2Fgit-blob-483f8de95b3964969123f06e22cb53e8e9152467%2Fimage3.png?alt=media)

***

#### Have more questions? Ask in our [Discord!](http://discord.gg/sansarofficial)
