Component:ValueCopy: Difference between revisions

From Resonite Wiki
m ProbablePrime moved page ValueCopy (Component) to Component:ValueCopy: Creating component Namespace
fixes
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages></languages>
{{Infobox Component
<translate>
|Image=ValueCopy`1Component.png
<!--T:1-->
|Name=Value Copy
{{stub}}
}}
 
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]].


<!--T:2-->
== Fields ==
== Fields ==
{{Table ComponentFields
{{Table ComponentFields
|Source|IField`1|TypeString0=IField<float>| The source to copy the value from.
|Source|{{RootFieldType|RelayRef`1|[[Type:IField`1|IField`1]]&lt;T&gt;}}|TypeAdv0=true| The source to copy the value from.
|Target|IField`1|TypeString1=IField<float>| The target to copy the value to.
|Target|{{RootFieldType|FieldDrive`1|T}}|TypeAdv1=true| The target to copy the value to.
|WriteBack|Bool| Allow Target to write back to Source.
|WriteBack|Bool| Allow Target to write back to Source. See [[Drives#Write Backs|write backs]].
}}
}}


<!--T:3-->
== Usage ==
== Usage ==
Drives the target's value with the source's value. When using WriteBack, changes made to the Target are local while editing it. When the user is done setting it, it writes via a network sync to change the Source value. If the Source and Target are the same, the value will be completely local, and no network sync happens when changing the value. When using the ValueCopy to make fields local like this, joining users will have the host's value by default.


<!--T:4-->
This component ensures that the value in the <code>Target</code> field is equal to the value in the <code>Source</code> field. To do this, it [[drives]] the <code>Target</code> field to give it exclusive access to the value, then whenever the value in the <code>Source</code> field updates, it will write the new value to the <code>Target</code> field.
 
When <code>WriteBack</code> 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 [[Component:ValueUserOverride|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 ==
== Examples ==
[[File:ValueCopyExample1.png | 512px | ValueCopy Example]]
A ValueField<bool>'s Value is being self driven with a WriteBack - making the Value local, and still changeable. Changes to this value will be local.


[[File:ValueCopyExample2.png | 512px | ValueCopy Example]]
<gallery>
A ValueField<int>'s Value is being driven to be 7 from another ValueField<int>'s Value. The one in pink is the one being driven.
File:ValueCopyExample2.png | 512px | A ValueField&lt;[[Type:int|int]]&gt;'s Value is being driven to be 7 from another ValueField&lt;int&gt;'s Value. The one in pink is the one being driven.
 
File:ValueCopyExample3.png | 512px | A ValueCopy with <code>WriteBack</code> enabled. The target field is being edited to 4, which changes the source field as well.
 
File:ValueCopyExample1.png | 512px | A ValueField&lt;[[Type:bool|int]]&gt;'s Value is being self driven with a WriteBack. Changes to this value will be local.
</gallery>
 
== See also ==


[[File:ValueCopyExample3.png | 512px | ValueCopy Example]]
* [[Component:ReferenceCopy]] for the same behavior but with [[reference types]].
The Target field is being edited to 4, to write back to the Source field.
* [[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.


<!--T:5-->
== Related Components ==
</translate>
[[Category:ComponentStubs]]
[[Category:Generics{{#translation:}}]]
[[Category:Generics{{#translation:}}]]
[[Category:Components{{#translation:}}|Value Copy`1]]
[[Category:Components{{#translation:}}|Value Copy`1]]
[[Category:Generic Components{{#translation:}}|Value Copy`1]]
[[Category:Components:Transform:Drivers{{#translation:}}|Value Copy`1]]
[[Category:Components:Transform:Drivers{{#translation:}}|Value Copy`1]]

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