# StateReference

> Identifies a state inside a visualization StateReference.Context so visualization changes can be applied to it.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.GraphToolkit.Editor.GraphVisualization](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization.md)
* **Assembly:** UnityEditor
* **Implements:** [IEquatable\<StateReference>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public readonly struct StateReference : IEquatable<StateReference>
```

## Remarks

Obtain a [StateReference](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference.md) from [Context.GetStateReference](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/context/getstatereference.md). The reference is only meaningful for the [StateReference.Context](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/context.md) that produced it. You can use its properties to set, retrieve, or clear customization for that specific state in the state machine canvas. Two [StateReference](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference.md) values are equal when they share the same [StateReference.StateID](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/stateid.md) and refer to the same [StateReference.Context](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/context.md) instance.

Additional Resources: [StateReference.Context](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/context.md), [Context.GetStateReference](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/context/getstatereference.md)

## Examples

```csharp
// Obtain a reference to a state by its ID, then drive its visual state.
using Context context = Registry.CreateVisualizationContext(stateMachineID);
StateReference stateRef = context.GetStateReference(stateID);

// Show a half-filled accent bar on the state.
stateRef.FillAmount = 50f;

// Replace the static fill with a looping progress animation.
context.Motion.Play(stateRef, animationSpeed: 1f);

// Stop the animation. The bar remains visible at the previously set fill amount.
context.Motion.Stop(stateRef);
```

## Properties

| Property                                                                                                                | Description                                                                                         |
| ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| [Context](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/context.md)       | Visualization context that produced the current state reference.                                    |
| [FillAmount](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/fillamount.md) | The progress fill amount displayed on the referenced state's accent bar, expressed as a percentage. |
| [StateID](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/stateid.md)       | Unique identifier of the state this reference points to.                                            |

## Methods

| Method                                                                                                                                  | Description                                                                                                                                                                |
| --------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [ClearCustomization](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/clearcustomization.md) | Clears all customization previously applied to the referenced state, removes any fill amount, and stops any looping animation.                                             |
| [Equals](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/equals.md)                         | Indicates whether the current [StateReference](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference.md) is equal to another object. |
| [GetHashCode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/gethashcode.md)               | Returns a hash code for the current [StateReference](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference.md).                      |

## Operators

| Operator                                                                                                                    | Description                                                                                                                                          |
| --------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| [operator ==](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/op-equality.md)   | Compares two [StateReference](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference.md) values for equality.   |
| [operator !=](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference/op-inequality.md) | Compares two [StateReference](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphvisualization/statereference.md) values for inequality. |
