Component:ValueCopy: Difference between revisions

From Resonite Wiki
overhaul
fixes
 
Line 4: Line 4:
}}
}}


The '''ValueCopy''' component is used to ensure that a value from one [[Type:IField|field]] is the same as another field. It accomplishes this by [[driving]] the target field with the option to write back values written to it.
The '''ValueCopy''' component is used to ensure that a value from one [[Type:IField|field]] is the same as another field via a one-way relation or a two-way relation with writeback. The source and target types must be [[value types]].


== Fields ==
== Fields ==
Line 34: Line 34:
== See also ==
== See also ==


* [[Component:ReferenceCopy]] for the same behavior but with [[reference types]].
* [[Component:ValueMultiDriver]] for forming this relation to multiple target fields.
* [[Component:ValueMultiDriver]] for forming this relation to multiple target fields.
* [[Component:ValueDriver]] for continuously updating a field from an [[Type:IValue|IValue]] source rather than a field.
* [[Component:ValueDriver]] for continuously updating a field from an [[Type:IValue|IValue]] source rather than a field.

Latest revision as of 15:17, 14 September 2025

Component image 
File:ValueCopy`1Component.png
Value Copy component as seen in the Scene Inspector

The ValueCopy component is used to ensure that a value from one field is the same as another field via a one-way relation or a two-way relation with writeback. The source and target types must be value types.

Fields

Fields
Name Type Description
persistent Bool Determines whether or not this item will be saved to the server.
UpdateOrder Int Controls the order in which this component is updated.
Enabled Bool Controls whether or not this component is enabled. Some components stop their functionality when this field is disabled, but some don't.
Source direct RelayRef`1<IField`1<T>> The source to copy the value from.
Target field drive of T The target to copy the value to.
WriteBack Bool Allow Target to write back to Source. See write backs.

Usage

This component ensures that the value in the Target field is equal to the value in the Source field. To do this, it drives the Target field to give it exclusive access to the value, then whenever the value in the Source field updates, it will write the new value to the Target field.

When WriteBack is enabled, the target field will have the ability to be changed. Changes made to the target field will then be written back to the source field.

Using a ValueCopy from a field to itself will essentially make the field read-only. If WriteBack is enabled, it presents an interesting combination of the locality of drives and writing of values: It will make the value of the field local to each individual user. This may be used as a version of ValueUserOverride that doesn't do any kind of network writes, but it should be noted that users joining the session will first receive the value from the host user before it gets changed. As such, it should only be used when the value doesn't quite matter specifically or gets updated frequently.

Examples

See also