unity – Why the UI text value is changing take affect only when returning back to the visual studio window and than back to the editor?

My guess is because I’m using OnValidate but is there another way to try to accomplish what I’m trying ?

The goal is use the drawn circle in one script information and use this information in another script.

For example the GameObject the draw circle script is attached to I want to get the Y position of that GameObject and assign the value to the other script specific variable in both Editor and Runtime modes.

This script draw a circle in this case around my player and I attached this script to a empty GameObject child of my player so I can change the circle height by changing the GameObject Y position :

using UnityEngine;
using System.Collections;
using System;

public class DrawRadiusAroundObject : MonoBehaviour
    (Range(1, 50)) public int segments = 50;
    (Range(1, 5)) public float xRadius = 5;
    (Range(1, 5)) public float yRadius = 5;
    (Range(0.1f, 5f)) public float width = 0.1f;
    public bool controlBothXradiusYradius = false;
    public bool draw = true;

    (SerializeField) private LineRenderer line;

    private void Start()
        if (!line) line = GetComponent<LineRenderer>();


    //private void Update()

    public void CreatePoints()
        line.enabled = true;
        line.widthMultiplier = width;
        line.useWorldSpace = false;
        line.widthMultiplier = width;
        line.positionCount = segments + 1;

        float x;
        float y;

        var angle = 20f;
        var points = new Vector3(segments + 1);
        for (int i = 0; i < segments + 1; i++)
            x = Mathf.Sin(Mathf.Deg2Rad * angle) * xRadius;
            y = Mathf.Cos(Mathf.Deg2Rad * angle) * yRadius;

            points(i) = new Vector3(x, 0f, y);

            angle += (380f / segments);

        // it's way more efficient to do this in one go!

    private float prevXRadius, prevYRadius;
    private int prevSegments;
    private float prevWidth;

    private void OnValidate()
        // Can't set up our line if the user hasn't connected it yet.
        if (!line) line = GetComponent<LineRenderer>();
        if (!line) return;

        if (!draw)
            // instead simply disable the component
            line.enabled = false;
            // Otherwise re-enable the component
            // This will simply re-use the previously created points
            line.enabled = true;

            if (xRadius != prevXRadius || yRadius != prevYRadius || segments != prevSegments || width != prevWidth)

                // Cache our most recently used values.
                prevXRadius = xRadius;
                prevYRadius = yRadius;
                prevSegments = segments;
                prevWidth = width;

            if (controlBothXradiusYradius)
                yRadius = xRadius;

The object with the drawn circle :

Drawn circle around the player

And this script is making an object the Target child to rotate around my player.
I want by using the drawn circle information to set the rotating variables.

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class SimpleRotate : MonoBehaviour
    public List<TextMeshProUGUI> uiText = new List<TextMeshProUGUI>();

    public DrawRadiusAroundObject drawAround;

    // Add this script to Cube(2)
    (Header("Add your turret"))
    public GameObject Turret;//to get the position in worldspace to which this gameObject will rotate around.

    (Header("The axis by which it will rotate around"))
    public Vector3 axis;//by which axis it will rotate. x,y or z.

    (Header("Angle covered per update"))
    public float angle; //or the speed of rotation.

    public float upperLimit, lowerLimit, delay;// upperLimit & lowerLimit: heighest & lowest height; 
    private float height, prevHeight, time;//height:height it is trying to reach(randomly generated); prevHeight:stores last value of height;delay in radomness; 

    // Update is called once per frame
    void Update()
        //Gets the position of your 'Turret' and rotates this gameObject around it by the 'axis' provided at speed 'angle' in degrees per update 
        transform.RotateAround(Turret.transform.position, axis.normalized, angle);
        time += Time.deltaTime;
        //Sets value of 'height' randomly within 'upperLimit' & 'lowerLimit' after delay 
        if (time > delay)
            prevHeight = height;
            height = Random.Range(lowerLimit, upperLimit);
            time = 0;
        //Mathf.Lerp changes height from 'prevHeight' to 'height' gradually (smooth transition)  
        transform.position = new Vector3(transform.position.x, Mathf.Lerp(prevHeight, height, time), transform.position.z);

        uiText(0).text = angle.ToString();
        uiText(1).text = upperLimit.ToString();
        uiText(2).text = lowerLimit.ToString();
        uiText(3).text = delay.ToString();

        upperLimit = drawAround.transform.position.y;

The object with the script that make Target object child to rotate around my player

Target is the basketball.

The basketball rotating around my player.

For example I tried to set the object Y position value on the Upper Limit variable in the SimpleRotate script.

Everything is getting update find in editor mode and runtime mode except the ui text.

First of all I’m not sure using (ExecuteAlways) in both scripts is the right way and second because I’m using OnValidate in the script that draw the circle the affecting on the variable upper limit is taking affect only when I validate by changing windows in the editor mode.