# Gradients in visual scripting ?

**URL:** https://discussions.unity.com/t/gradients-in-visual-scripting/900774
**Category:** Visual Scripting
**Tags:** Visual-Scripting, Question, com\_unity\_visualscripting
**Created:** [November 21, 2022, 11:12am UTC](https://discussions.unity.com/t/gradients-in-visual-scripting/900774 "2022-11-21T11:12:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MoussaNeggaz](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@MoussaNeggaz](https://discussions.unity.com/u/MoussaNeggaz)
#### Post date: [November 21, 2022, 11:12am UTC](https://discussions.unity.com/t/gradients-in-visual-scripting/900774/1 "2022-11-21T11:12:59Z")

</div>

Hello,  
I would like to do an HP bar wich changes colors when the player loses HP. However i don’t know how to use gradients in visual scripting, could someone help me with that ?  
Thanks a lot !

---

<div class="post-metadata">

### Author: ![TimHermelink](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/timhermelink/32/310051_2.png) [@TimHermelink](https://discussions.unity.com/u/TimHermelink)
#### Post date: [January 5, 2023, 4:11pm UTC](https://discussions.unity.com/t/gradients-in-visual-scripting/900774/2 "2023-01-05T16:11:54Z")

</div>

You can use “Color.lerp” for this.  
If your HP varible goes from 0 to 100, make sure to divide it by 100 so it ends up being 0 to 1

---

<div class="post-metadata">

### Author: ![PanthenEye](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/pantheneye/32/83051_2.png) [@PanthenEye](https://discussions.unity.com/u/PanthenEye)
#### Post date: [January 5, 2023, 5:13pm UTC](https://discussions.unity.com/t/gradients-in-visual-scripting/900774/3 "2023-01-05T17:13:35Z")

</div>

You could also grab Dotween from the asset store and use Image.DOColor(Color to, float duration) shortcut.

---

<div class="post-metadata">

### Author: ![Soraphis1](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/soraphis1/32/285231_2.png) [@Soraphis1](https://discussions.unity.com/u/Soraphis1)
#### Post date: [January 6, 2023, 9:55am UTC](https://discussions.unity.com/t/gradients-in-visual-scripting/900774/4 "2023-01-06T09:55:19Z")

</div>

Sadly, “Gradient” is missing in the stuff you can do with VisualScripting, even though it’s perfectly serializable by unity, you can’t create a GradientVariable in VisualScripting ‍♂️

A Gradient can obviously do a lot more stuff than a simple lerp.

First I thought: okay, just create a custom node for gradients should be easy, but the visual scripting system just shows a warning instead of the GradientField, that there is no drawer for it.  
I then tried to wrap the Gradient into a custom type with a custom drawer, but it just ignored my custom drawer.

I then tried to add “Gradient” in the project settings \> Visual Scripting to the Type Options and, while it now shows as a type and you can use all of it’s fuctions, you can’t setup the Gradient in the inspector. You’d have to create a script which modify’s the Gradient on the “Variables”-Component for you.

**Edit:**

Okay, now it worked:

add this script in an Editor folder or in an Editor asmdef:

```csharp
[CustomPropertyDrawer(typeof(Gradient))]
public class GradientPropertyDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // yes, this is stupid, and only for the visual scripting system:
        EditorGUI.PropertyField(position, property, label);
    }
}

```

- Go To: Project settings \> Visual Scripting
- in Type Options add “Gradient”
- Press Button: Regenerate Node Library
- Press Button Generate in “Custom Inspector Properties”

Now you can use Gradients in Visual Scripting like everything else

 ![8709564--1176738--upload_2023-1-6_11-6-24.png](https://europe1.discourse-cdn.com/unity/original/3X/b/0/b0172fde0d7a7082db1aa6855d19c644a23e7250.png)

---

<div class="post-metadata">

### Author: ![RudyRG3D](https://avatars.discourse-cdn.com/v4/letter/r/e5b9ba/32.png) [@RudyRG3D](https://discussions.unity.com/u/RudyRG3D)
#### Post date: [March 8, 2025, 1:38am UTC](https://discussions.unity.com/t/gradients-in-visual-scripting/900774/5 "2025-03-08T01:38:22Z")

</div>

Thanks for posting this! It would be great if Unity could just Update this internally, as well. I was getting the same thing while adding the Node in Settings, where it was not available in the Inspector.

Update: Just wanted to say this works _amazingly_!!! I am able to set different Gradients for my VFX Graph(s) now, via Visual Scripting. Thanks Again!
