Referencing scene components with scripts

Scripts 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.

In this article, we'll use the terms source and target. The source is a script parameter 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.

Copy_component_source.png Paste_component_target.png
Right-click the component in the Object Structure panel and select Copy. Right-click the component parameter in the script's properties and select Paste.


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.

image2.png image4.png image3.png
When a script parameter attempts to point at a target that is no longer available, the parameter reads (not found). When you build a scene that contains missing targets, you receive a warning when the build is completed. When you attempt to create a collection with incomplete references, you receive a warning and the option to cancel.


Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request


Article is closed for comments.