Hello, I’m attempting to change the effect distance of an Outline component that I’ve attached to a UI Text object at run time. I’ve attached the following simple script to the Text object which should theoretically reduce the effect distance of an outline over a small period of time.

using UnityEngine;
using UnityEngine.UI;

public class OutlineXAdjust : MonoBehaviour
{
	public float speed = 10;
	private Outline outline;

	void Start()
	{
		outline = GetComponent<Outline>();
	}

	void Update()
	{
		outline.effectDistance.Set(Mathf.MoveTowards(outline.effectDistance.x, 0, Time.deltaTime * speed), 0);
		Debug.Log(outline.effectDistance.x);
    }
}

For some magical reason however, nothing happens, and the debug continually logs the starting value of outline.effectDistance.x I’ve tried adjusting the effectColor as well but have had no success there either. Anyone have any idea what the problem is? Many thanks in advance

Hello!

Because effectDistance is a struct.

Replace your Update()

 void Update()
 {
     outline.effectDistance = new Vector2(Mathf.MoveTowards(outline.effectDistance.x, 0, Time.deltaTime * speed), 0);
     Debug.Log(outline.effectDistance.x);
 }

You are welcome. (4 minutes to answer? Not my best score…)