# Referencing Scene Components

## Referencing scene components with scripts

[Scripts](/scripting/api-overview.md) 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 of connected objects for sale in the [Sansar Store](/store/selling/manage-listings.md).

In this article, we'll use the terms _source_ and _target_. The _source_ is a [script parameter](/scripting/guides/setting-script-parameters.md) 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.



### 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 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, 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.



<div id="have-more-questions-ask-in-our-discord"></div>